X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fsync%2Ffiles_test.go;h=635501195860b35b79333213d96f5aa6510ecf77;hb=d12e83d4d64b295b8da5c0506d44e94a330ab272;hp=e7864ba8b8080e489da5964663c1496308599bd1;hpb=3473766d8afb07cb0685694656947883cbbd1138;p=safcm%2Fsafcm.git diff --git a/cmd/safcm-remote/sync/files_test.go b/cmd/safcm-remote/sync/files_test.go index e7864ba..6355011 100644 --- a/cmd/safcm-remote/sync/files_test.go +++ b/cmd/safcm-remote/sync/files_test.go @@ -53,13 +53,16 @@ func TestSyncFiles(t *testing.T) { } user, uid, group, gid := ft.CurrentUserAndGroup() + skipUnlessCiRun := len(os.Getenv("SAFCM_CI_RUN")) == 0 + tmpTestFilePath := "/tmp/safcm-sync-files-test-file" tests := []struct { name string + skip bool req safcm.MsgSyncReq prepare func() - triggers []string + expTriggers []string expFiles []ft.File expResp safcm.MsgSyncResp expDbg []string @@ -74,6 +77,7 @@ func TestSyncFiles(t *testing.T) { { "basic: create", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -157,6 +161,7 @@ func TestSyncFiles(t *testing.T) { { "basic: no change", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -211,6 +216,7 @@ func TestSyncFiles(t *testing.T) { { "invalid File: user", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -234,6 +240,7 @@ func TestSyncFiles(t *testing.T) { }, { "invalid File: group", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -261,43 +268,32 @@ func TestSyncFiles(t *testing.T) { // don't want to modify the running system. Use this // test (and the one below for triggers) as a basic // check that absolute paths work. + // + // Use numeric IDs as not all systems use root/root; + // for example BSDs use root/wheel. "absolute paths: no change", + skipUnlessCiRun, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ "/": { Path: "/", Mode: fs.ModeDir | 0755, - User: "root", - Uid: -1, - Group: "root", - Gid: -1, + Uid: 0, + Gid: 0, OrigGroup: "group", }, "/etc": { Path: "/etc", Mode: fs.ModeDir | 0755, - User: "root", - Uid: -1, - Group: "root", - Gid: -1, + Uid: 0, + Gid: 0, OrigGroup: "group", }, "/tmp": { Path: "/tmp", Mode: fs.ModeDir | 0777 | fs.ModeSticky, - User: "root", - Uid: -1, - Group: "root", - Gid: -1, - OrigGroup: "group", - }, - "/var/tmp": { - Path: "/var/tmp", - Mode: fs.ModeDir | 0777 | fs.ModeSticky, - User: "root", - Uid: -1, - Group: "root", - Gid: -1, + Uid: 0, + Gid: 0, OrigGroup: "group", }, }, @@ -312,13 +308,13 @@ func TestSyncFiles(t *testing.T) { `4: sync remote: files: "/" (group): unchanged`, `4: sync remote: files: "/etc" (group): unchanged`, `4: sync remote: files: "/tmp" (group): unchanged`, - `4: sync remote: files: "/var/tmp" (group): unchanged`, }, nil, }, { "triggers: no change", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -382,6 +378,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: change root", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -474,6 +471,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: change middle", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -564,6 +562,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: change leaf", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -650,6 +649,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: multiple changes", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -751,15 +751,14 @@ func TestSyncFiles(t *testing.T) { { "triggers: absolute paths", + skipUnlessCiRun, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ "/": { Path: "/", Mode: fs.ModeDir | 0755, - User: "root", - Uid: -1, - Group: "root", - Gid: -1, + Uid: 0, + Gid: 0, OrigGroup: "group", TriggerCommands: []string{ "echo trigger /", @@ -768,10 +767,8 @@ func TestSyncFiles(t *testing.T) { "/tmp": { Path: "/tmp", Mode: fs.ModeDir | 0777 | fs.ModeSticky, - User: "root", - Uid: -1, - Group: "root", - Gid: -1, + Uid: 0, + Gid: 0, OrigGroup: "group", TriggerCommands: []string{ "echo trigger /tmp", @@ -789,16 +786,7 @@ func TestSyncFiles(t *testing.T) { }, }, }, - func() { - // This is slightly racy but the file name - // should be rare enough that this isn't an - // issue - _, err := os.Stat(tmpTestFilePath) - if err == nil { - t.Fatalf("%q exists, aborting", - tmpTestFilePath) - } - }, + nil, []string{ "/", "/tmp", @@ -840,6 +828,10 @@ func TestSyncFiles(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { + if tc.skip { + t.SkipNow() + } + // Create separate test directory for each test case path := filepath.Join(cwd, "testdata", "files-"+tc.name) err = os.Mkdir(path, 0700) @@ -877,7 +869,7 @@ func TestSyncFiles(t *testing.T) { testutil.AssertEqual(t, "resp", s.resp, tc.expResp) testutil.AssertEqual(t, "triggers", - s.triggers, tc.triggers) + s.triggers, tc.expTriggers) }) }