]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - cmd/safcm/sync_changes_test.go
tests: add and use testutil package to reduce duplication
[safcm/safcm.git] / cmd / safcm / sync_changes_test.go
index 767564fd14221a2c37405349b9bc867a777cdaa0..e5efe1d26bb38b44bc5de84bacc517b9b3877062 100644 (file)
@@ -19,10 +19,9 @@ import (
        "io/fs"
        "testing"
 
-       "github.com/google/go-cmp/cmp"
-
        "ruderich.org/simon/safcm"
        "ruderich.org/simon/safcm/cmd/safcm/config"
+       "ruderich.org/simon/safcm/testutil"
 )
 
 func TestFormatFileChanges(t *testing.T) {
@@ -284,17 +283,14 @@ func TestFormatFileChanges(t *testing.T) {
 
        for _, tc := range tests {
                t.Run(tc.name, func(t *testing.T) {
-               s := &Sync{
-                       config: &config.Config{
-                               DryRun: tc.dryRun,
-                       },
-               }
+                       s := &Sync{
+                               config: &config.Config{
+                                       DryRun: tc.dryRun,
+                               },
+                       }
 
-               res := s.formatFileChanges(tc.changes)
-               if tc.exp != res {
-                       t.Errorf("res: %s",
-                               cmp.Diff(tc.exp, res))
-               }
+                       res := s.formatFileChanges(tc.changes)
+                       testutil.AssertEqual(t, "res", res, tc.exp)
                })
        }
 }
@@ -357,17 +353,14 @@ func TestFormatPackageChanges(t *testing.T) {
 
        for _, tc := range tests {
                t.Run(tc.name, func(t *testing.T) {
-               s := &Sync{
-                       config: &config.Config{
-                               DryRun: tc.dryRun,
-                       },
-               }
+                       s := &Sync{
+                               config: &config.Config{
+                                       DryRun: tc.dryRun,
+                               },
+                       }
 
-               res := s.formatPackageChanges(tc.changes)
-               if tc.exp != res {
-                       t.Errorf("res: %s",
-                               cmp.Diff(tc.exp, res))
-               }
+                       res := s.formatPackageChanges(tc.changes)
+                       testutil.AssertEqual(t, "res", res, tc.exp)
                })
        }
 }
@@ -452,17 +445,14 @@ func TestFormatServiceChanges(t *testing.T) {
 
        for _, tc := range tests {
                t.Run(tc.name, func(t *testing.T) {
-               s := &Sync{
-                       config: &config.Config{
-                               DryRun: tc.dryRun,
-                       },
-               }
+                       s := &Sync{
+                               config: &config.Config{
+                                       DryRun: tc.dryRun,
+                               },
+                       }
 
-               res := s.formatServiceChanges(tc.changes)
-               if tc.exp != res {
-                       t.Errorf("res: %s",
-                               cmp.Diff(tc.exp, res))
-               }
+                       res := s.formatServiceChanges(tc.changes)
+                       testutil.AssertEqual(t, "res", res, tc.exp)
                })
        }
 }
@@ -664,18 +654,15 @@ func TestFormatCommandChanges(t *testing.T) {
 
        for _, tc := range tests {
                t.Run(tc.name, func(t *testing.T) {
-               s := &Sync{
-                       config: &config.Config{
-                               DryRun: tc.dryRun,
-                               Quiet:  tc.quiet,
-                       },
-               }
+                       s := &Sync{
+                               config: &config.Config{
+                                       DryRun: tc.dryRun,
+                                       Quiet:  tc.quiet,
+                               },
+                       }
 
-               res := s.formatCommandChanges(tc.changes)
-               if tc.exp != res {
-                       t.Errorf("res: %s",
-                               cmp.Diff(tc.exp, res))
-               }
+                       res := s.formatCommandChanges(tc.changes)
+                       testutil.AssertEqual(t, "res", res, tc.exp)
                })
        }
 }