]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - cmd/safcm-remote/sync/packages_debian_test.go
sync: remove "detected" log message in packages/services
[safcm/safcm.git] / cmd / safcm-remote / sync / packages_debian_test.go
index 51b6b746865da76bee636a81e7717a9d1ca9b995..a51a6a9d3f319abc966fbcec473a2c4e3a103d0d 100644 (file)
@@ -20,12 +20,10 @@ import (
        "fmt"
        "os"
        "os/exec"
-       "reflect"
        "testing"
 
-       "github.com/google/go-cmp/cmp"
-
        "ruderich.org/simon/safcm"
+       "ruderich.org/simon/safcm/testutil"
 )
 
 func TestSyncPackagesDebian(t *testing.T) {
@@ -42,7 +40,7 @@ func TestSyncPackagesDebian(t *testing.T) {
        }{
 
                // NOTE: Also update MsgSyncResp in safcm test cases when
-               // changing anything here!
+               // changing the MsgSyncResp struct!
 
                {
                        "packages already installed",
@@ -75,7 +73,7 @@ install ok installed  package-two
                                Stderr: &bytes.Buffer{},
                        }},
                        []string{
-                               "4: sync remote: packages: detected debian",
+                               "4: sync remote: packages: checking package-one package-two (debian detected)",
                                `4: sync remote: packages: running "/usr/bin/dpkg-query" "--show" "--showformat=${Status}\\t${Package}\\n"`,
                                `5: sync remote: packages: command stdout:
 install ok installed   golang
@@ -86,7 +84,6 @@ install ok installed  golang-1.16-src
 hold ok installed      package-one
 install ok installed   package-two
 `,
-                               "4: sync remote: packages: checking package-one package-two",
                        },
                        safcm.MsgSyncResp{},
                        nil,
@@ -140,7 +137,7 @@ install ok installed        package-two
                                ),
                        }},
                        []string{
-                               "4: sync remote: packages: detected debian",
+                               "4: sync remote: packages: checking package-one package-two package-three (debian detected)",
                                `4: sync remote: packages: running "/usr/bin/dpkg-query" "--show" "--showformat=${Status}\\t${Package}\\n"`,
                                `5: sync remote: packages: command stdout:
 install ok installed   golang
@@ -150,7 +147,6 @@ install ok installed        golang-1.16-go
 install ok installed   golang-1.16-src
 install ok installed   package-two
 `,
-                               "4: sync remote: packages: checking package-one package-two package-three",
                                "3: sync remote: packages: installing package-one package-three",
                                `4: sync remote: packages: running "/usr/bin/apt-get" "install" "--assume-yes" "--no-upgrade" "--no-install-recommends" "-o" "Dpkg::Options::=--force-confdef" "-o" "Dpkg::Options::=--force-confold" "package-one" "package-three"`,
                                "5: sync remote: packages: command output:\nfake stdout/stderr",
@@ -217,7 +213,7 @@ install ok installed        golang-1.16-src
                                ),
                        }},
                        []string{
-                               "4: sync remote: packages: detected debian",
+                               "4: sync remote: packages: checking package-one package-two (debian detected)",
                                `4: sync remote: packages: running "/usr/bin/dpkg-query" "--show" "--showformat=${Status}\\t${Package}\\n"`,
                                `5: sync remote: packages: command stdout:
 install ok installed   golang
@@ -226,7 +222,6 @@ install ok installed        golang-1.16-doc
 install ok installed   golang-1.16-go
 install ok installed   golang-1.16-src
 `,
-                               "4: sync remote: packages: checking package-one package-two",
                                "3: sync remote: packages: installing package-one package-two",
                                `4: sync remote: packages: running "/usr/bin/apt-get" "install" "--assume-yes" "--no-upgrade" "--no-install-recommends" "-o" "Dpkg::Options::=--force-confdef" "-o" "Dpkg::Options::=--force-confold" "package-one" "package-two"`,
                                "5: sync remote: packages: command output:\nfake stdout/stderr",
@@ -274,7 +269,7 @@ install ok installed        golang-1.16-src
                                Stderr: &bytes.Buffer{},
                        }},
                        []string{
-                               "4: sync remote: packages: detected debian",
+                               "4: sync remote: packages: checking package-one package-two (debian detected)",
                                `4: sync remote: packages: running "/usr/bin/dpkg-query" "--show" "--showformat=${Status}\\t${Package}\\n"`,
                                `5: sync remote: packages: command stdout:
 install ok installed   golang
@@ -283,7 +278,6 @@ install ok installed        golang-1.16-doc
 install ok installed   golang-1.16-go
 install ok installed   golang-1.16-src
 `,
-                               "4: sync remote: packages: checking package-one package-two",
                        },
                        safcm.MsgSyncResp{
                                PackageChanges: []safcm.PackageChange{
@@ -301,30 +295,20 @@ install ok installed      golang-1.16-src
 
        for _, tc := range tests {
                t.Run(tc.name, func(t *testing.T) {
-               s, res := prepareSync(tc.req, &testRunner{
-                       t:         t,
-                       expCmds:   tc.expCmds,
-                       resStdout: tc.stdout,
-                       resStderr: tc.stderr,
-                       resError:  tc.errors,
-               })
+                       s, res := prepareSync(tc.req, &testRunner{
+                               t:         t,
+                               expCmds:   tc.expCmds,
+                               resStdout: tc.stdout,
+                               resStderr: tc.stderr,
+                               resError:  tc.errors,
+                       })
 
-               err := s.syncPackagesDebian()
-               // 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)
-               }
-               dbg := res.Wait()
+                       err := s.syncPackagesDebian()
+                       testutil.AssertErrorEqual(t, "err", err, tc.expErr)
+                       dbg := res.Wait()
 
-               if !reflect.DeepEqual(tc.expResp, s.resp) {
-                       t.Errorf("resp: %s",
-                               cmp.Diff(tc.expResp, s.resp))
-               }
-               if !reflect.DeepEqual(tc.expDbg, dbg) {
-                       t.Errorf("dbg: %s",
-                               cmp.Diff(tc.expDbg, dbg))
-               }
+                       testutil.AssertEqual(t, "resp", s.resp, tc.expResp)
+                       testutil.AssertEqual(t, "dbg", dbg, tc.expDbg)
                })
        }
 }