tmpTestFilePath := "/tmp/safcm-sync-files-test-file"
tests := []struct {
- name string
- skip bool
- req safcm.MsgSyncReq
- prepare func()
- triggers []string
- expFiles []ft.File
- expResp safcm.MsgSyncResp
- expDbg []string
- expErr error
+ name string
+ skip bool
+ req safcm.MsgSyncReq
+ prepare func()
+ expTriggers []string
+ 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.
},
},
func() {
- err = os.Chmod(".", 0750)
- if err != nil {
- panic(err)
- }
+ ft.CreateDirectoryExists(".", 0750)
ft.CreateDirectory("dir", 0755)
ft.CreateFile("dir/file", "content\n", 0644)
},
// 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)
}
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
testutil.AssertEqual(t, "resp", s.resp, tc.expResp)
testutil.AssertEqual(t, "triggers",
- s.triggers, tc.triggers)
+ s.triggers, tc.expTriggers)
})
}
}{
// 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
Group: group,
Gid: gid,
},
- DataDiff: "Binary files differ, cannot show diff",
+ DataDiff: "Binary files differ (3 -> 4 bytes), cannot show diff",
},
},
},
Gid: gid,
},
DataDiff: `@@ -1,2 +1,2 @@
--<binary content>
+-<binary content, 3 bytes>
+content
`,
},
DataDiff: `@@ -1,2 +1,2 @@
-content
-+<binary content>
++<binary content, 4 bytes>
`,
},
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)
}
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