main_test.go 910 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. package main
  5. import (
  6. "bytes"
  7. "io/ioutil"
  8. "testing"
  9. )
  10. const (
  11. goldFile = "testdata/test.go.gold"
  12. inFile = "testdata/test.go.in"
  13. )
  14. func TestImportSort(t *testing.T) {
  15. in, err := ioutil.ReadFile(inFile)
  16. if err != nil {
  17. t.Fatal(err)
  18. }
  19. gold, err := ioutil.ReadFile(goldFile)
  20. if err != nil {
  21. t.Fatal(err)
  22. }
  23. sections := []string{"foobar", "cvshub.com/foobar"}
  24. if out, err := genFile(gold, sections); err != nil {
  25. t.Fatal(err)
  26. } else if !bytes.Equal(out, gold) {
  27. t.Errorf("importsort on %s file produced a change", goldFile)
  28. t.Log(string(out))
  29. }
  30. if out, err := genFile(in, sections); err != nil {
  31. t.Fatal(err)
  32. } else if !bytes.Equal(out, gold) {
  33. t.Errorf("importsort on %s different than gold", inFile)
  34. t.Log(string(out))
  35. }
  36. }