]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - cmd/safcm-remote/sync/files_test.go
tests: improve another comment
[safcm/safcm.git] / cmd / safcm-remote / sync / files_test.go
index 635501195860b35b79333213d96f5aa6510ecf77..57d27c7fa8e043b06543387a1a15a720fcdb0755 100644 (file)
@@ -58,19 +58,19 @@ func TestSyncFiles(t *testing.T) {
        tmpTestFilePath := "/tmp/safcm-sync-files-test-file"
 
        tests := []struct {
-               name     string
-               skip     bool
-               req      safcm.MsgSyncReq
-               prepare  func()
+               name        string
+               skip        bool
+               req         safcm.MsgSyncReq
+               prepare     func()
                expTriggers []string
-               expFiles []ft.File
-               expResp  safcm.MsgSyncResp
-               expDbg   []string
-               expErr   error
+               expFiles    []ft.File
+               expResp     safcm.MsgSyncResp
+               expDbg      []string
+               expErr      error
        }{
 
                // NOTE: Also update MsgSyncResp in safcm test cases when
-               // changing anything here!
+               // changing the MsgSyncResp struct!
 
                // See TestSyncFile() for most file related tests. This
                // function only tests the overall results and triggers.
@@ -415,10 +415,7 @@ func TestSyncFiles(t *testing.T) {
                                },
                        },
                        func() {
-                               err = os.Chmod(".", 0750)
-                               if err != nil {
-                                       panic(err)
-                               }
+                               ft.CreateDirectoryExists(".", 0750)
                                ft.CreateDirectory("dir", 0755)
                                ft.CreateFile("dir/file", "content\n", 0644)
                        },
@@ -834,7 +831,7 @@ func TestSyncFiles(t *testing.T) {
 
                        // Create separate test directory for each test case
                        path := filepath.Join(cwd, "testdata", "files-"+tc.name)
-                       err = os.Mkdir(path, 0700)
+                       err := os.Mkdir(path, 0700)
                        if err != nil {
                                t.Fatal(err)
                        }
@@ -850,9 +847,12 @@ func TestSyncFiles(t *testing.T) {
                        s, res := prepareSync(tc.req, &testRunner{
                                t: t,
                        })
-                       s.setDefaults()
+                       err = s.setDefaults()
+                       if err != nil {
+                               t.Fatal(err)
+                       }
 
-                       err := s.syncFiles()
+                       err = s.syncFiles()
                        testutil.AssertErrorEqual(t, "err", err, tc.expErr)
                        dbg := res.Wait()
                        // Remove random file names from result
@@ -917,7 +917,7 @@ func TestSyncFile(t *testing.T) {
        }{
 
                // NOTE: Also update MsgSyncResp in safcm test cases when
-               // changing anything here!
+               // changing the MsgSyncResp struct!
 
                // TODO: Add tests for chown and run them only as root
 
@@ -2239,7 +2239,7 @@ file
                                                        Group: group,
                                                        Gid:   gid,
                                                },
-                                               DataDiff: "Binary files differ, cannot show diff",
+                                               DataDiff: "Binary files differ (3 -> 4 bytes), cannot show diff",
                                        },
                                },
                        },
@@ -2295,7 +2295,7 @@ file
                                                        Gid:   gid,
                                                },
                                                DataDiff: `@@ -1,2 +1,2 @@
--<binary content>
+-<binary content, 3 bytes>
 +content
  
 `,
@@ -2355,7 +2355,7 @@ file
                                                },
                                                DataDiff: `@@ -1,2 +1,2 @@
 -content
-+<binary content>
++<binary content, 4 bytes>
  
 `,
                                        },
@@ -2374,7 +2374,7 @@ file
                t.Run(tc.name, func(t *testing.T) {
                        // Create separate test directory for each test case
                        path := filepath.Join(cwd, "testdata", "file-"+tc.name)
-                       err = os.Mkdir(path, 0700)
+                       err := os.Mkdir(path, 0700)
                        if err != nil {
                                t.Fatal(err)
                        }
@@ -2390,13 +2390,16 @@ file
                        s, res := prepareSync(tc.req, &testRunner{
                                t: t,
                        })
-                       s.setDefaults()
+                       err = s.setDefaults()
+                       if err != nil {
+                               t.Fatal(err)
+                       }
 
                        // Deterministic temporary symlink names
                        rand.Seed(0)
 
                        var changed bool
-                       err := s.syncFile(tc.file, &changed)
+                       err = s.syncFile(tc.file, &changed)
                        testutil.AssertErrorEqual(t, "err", err, tc.expErr)
                        dbg := res.Wait()
                        // Remove random file names from result