github.com/aristanetworks/goarista@v0.0.0-20240514173732-cca2755bbd44/cmd/importsort/main_test.go (about)

     1  // Copyright (c) 2017 Arista Networks, Inc.
     2  // Use of this source code is governed by the Apache License 2.0
     3  // that can be found in the COPYING file.
     4  
     5  package main
     6  
     7  import (
     8  	"bytes"
     9  	"io/ioutil"
    10  	"testing"
    11  )
    12  
    13  const (
    14  	goldFile = "testdata/test.go.gold"
    15  	inFile   = "testdata/test.go.in"
    16  )
    17  
    18  func TestImportSort(t *testing.T) {
    19  	in, err := ioutil.ReadFile(inFile)
    20  	if err != nil {
    21  		t.Fatal(err)
    22  	}
    23  	gold, err := ioutil.ReadFile(goldFile)
    24  	if err != nil {
    25  		t.Fatal(err)
    26  	}
    27  	sections := []string{"foobar", "cvshub.com/foobar"}
    28  	if out, err := genFile(gold, sections); err != nil {
    29  		t.Fatal(err)
    30  	} else if !bytes.Equal(out, gold) {
    31  		t.Errorf("importsort on %s file produced a change", goldFile)
    32  		t.Log(string(out))
    33  	}
    34  	if out, err := genFile(in, sections); err != nil {
    35  		t.Fatal(err)
    36  	} else if !bytes.Equal(out, gold) {
    37  		t.Errorf("importsort on %s different than gold", inFile)
    38  		t.Log(string(out))
    39  	}
    40  }