"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) {
}
_, 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
},
},
nil,
- fmt.Errorf("open file: too many levels of symbolic links"),
+ fmt.Errorf(symlinkExists),
},
{
"exists: fifo",
}
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)
- }
+ 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))
- }
+ testutil.AssertEqual(t, "files", files, tc.expFiles)
})
}