]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - cmd/safcm/config/groups_test.go
tests: add and use testutil package to reduce duplication
[safcm/safcm.git] / cmd / safcm / config / groups_test.go
index cf6cd6e088cd48d3789fb2f618f903eb1e420dcc..9c0acda892585577510a26d3eab5640694fecfb3 100644 (file)
@@ -19,10 +19,9 @@ import (
        "fmt"
        "os"
        "path/filepath"
-       "reflect"
        "testing"
 
-       "github.com/google/go-cmp/cmp"
+       "ruderich.org/simon/safcm/testutil"
 )
 
 func TestLoadGroups(t *testing.T) {
@@ -193,15 +192,8 @@ func TestLoadGroups(t *testing.T) {
                        }
 
                        res, err := LoadGroups(tc.cfg, tc.hosts)
-
-                       if !reflect.DeepEqual(tc.exp, res) {
-                               t.Errorf("res: %s", cmp.Diff(tc.exp, res))
-                       }
-                       // 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, "res", res, tc.exp)
+                       testutil.AssertErrorEqual(t, "err", err, tc.expErr)
                })
        }
 }
@@ -315,14 +307,8 @@ func TestResolveHostGroups(t *testing.T) {
                t.Run(tc.name, func(t *testing.T) {
                        res, err := ResolveHostGroups(tc.host, allGroups,
                                tc.detected)
-                       if !reflect.DeepEqual(tc.exp, res) {
-                               t.Errorf("res: %s", cmp.Diff(tc.exp, res))
-                       }
-                       // 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, "res", res, tc.exp)
+                       testutil.AssertErrorEqual(t, "err", err, tc.expErr)
                })
        }
 }