]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - cmd/safcm-remote/ainsl/ainsl_test.go
Add basic support for FreeBSD
[safcm/safcm.git] / cmd / safcm-remote / ainsl / ainsl_test.go
index 564bc37d99fde46e81ebbe305d27ee838d59b5f1..8e9b0c121a268747d2a234dab0e1a045927fd55f 100644 (file)
@@ -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",
@@ -310,24 +315,15 @@ func TestHandle(t *testing.T) {
                        }
 
                        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)
                })
        }