X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fainsl%2Fainsl_test.go;h=8e9b0c121a268747d2a234dab0e1a045927fd55f;hb=006a69a50239a27ba7929c513897ef19259e06af;hp=e4d6b46ddebeecb8cd0906f9c0c6052b55acdcd2;hpb=992eaae7fec45c2d58fff89d1bc0ae920a899296;p=safcm%2Fsafcm.git diff --git a/cmd/safcm-remote/ainsl/ainsl_test.go b/cmd/safcm-remote/ainsl/ainsl_test.go index e4d6b46..8e9b0c1 100644 --- a/cmd/safcm-remote/ainsl/ainsl_test.go +++ b/cmd/safcm-remote/ainsl/ainsl_test.go @@ -20,13 +20,12 @@ import ( "io/fs" "os" "path/filepath" - "reflect" + "runtime" "syscall" "testing" - "github.com/google/go-cmp/cmp" - ft "ruderich.org/simon/safcm/cmd/safcm-remote/sync/filetest" + "ruderich.org/simon/safcm/testutil" ) func TestHandle(t *testing.T) { @@ -55,6 +54,12 @@ func TestHandle(t *testing.T) { } _, uid, _, gid := ft.CurrentUserAndGroup() + symlinkExists := "open file: too many levels of symbolic links" + if runtime.GOOS == "freebsd" { + // EMLINK instead of ELOOP + symlinkExists = "open file: too many links" + } + tests := []struct { name string path string @@ -270,7 +275,7 @@ func TestHandle(t *testing.T) { }, }, nil, - fmt.Errorf("open file: too many levels of symbolic links"), + fmt.Errorf(symlinkExists), }, { "exists: fifo", @@ -294,40 +299,31 @@ func TestHandle(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - // Create separate test directory for each test case - path := filepath.Join(cwd, "testdata", tc.name) - err = os.Mkdir(path, 0700) - if err != nil { - t.Fatal(err) - } - err = os.Chdir(path) - if err != nil { - t.Fatal(err) - } + // Create separate test directory for each test case + path := filepath.Join(cwd, "testdata", tc.name) + err = os.Mkdir(path, 0700) + if err != nil { + t.Fatal(err) + } + err = os.Chdir(path) + if err != nil { + t.Fatal(err) + } - if tc.prepare != nil { - tc.prepare() - } + if tc.prepare != nil { + tc.prepare() + } - changes, err := handle(tc.path, tc.line, tc.create) - if !reflect.DeepEqual(tc.expChanges, changes) { - t.Errorf("changes: %s", - cmp.Diff(tc.expChanges, changes)) - } - // Ugly but the simplest way to compare errors (including nil) - if fmt.Sprintf("%s", err) != fmt.Sprintf("%s", tc.expErr) { - t.Errorf("err = %#v, want %#v", - err, tc.expErr) - } + changes, err := handle(tc.path, tc.line, tc.create) + testutil.AssertEqual(t, "changes", + changes, tc.expChanges) + testutil.AssertErrorEqual(t, "err", err, tc.expErr) - files, err := ft.WalkDir(path) - if err != nil { - t.Fatal(err) - } - if !reflect.DeepEqual(tc.expFiles, files) { - t.Errorf("files: %s", - cmp.Diff(tc.expFiles, files)) - } + files, err := ft.WalkDir(path) + if err != nil { + t.Fatal(err) + } + testutil.AssertEqual(t, "files", files, tc.expFiles) }) }