X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fsync%2Ffiles_test.go;h=bd5eac9930c31b8978efe8060f491dd859b9d604;hb=e4c6a178848145c8dba68ed054cbb48dcecccf65;hp=91a85befb83c24d9ea494e991e6699318c0289f8;hpb=583a2695a3ddc9c98e0a03d9f1bad8df30afe887;p=safcm%2Fsafcm.git diff --git a/cmd/safcm-remote/sync/files_test.go b/cmd/safcm-remote/sync/files_test.go index 91a85be..bd5eac9 100644 --- a/cmd/safcm-remote/sync/files_test.go +++ b/cmd/safcm-remote/sync/files_test.go @@ -53,10 +53,13 @@ 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 @@ -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{ ".": { @@ -265,6 +272,7 @@ func TestSyncFiles(t *testing.T) { // 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{ "/": { @@ -288,13 +296,6 @@ func TestSyncFiles(t *testing.T) { Gid: 0, OrigGroup: "group", }, - "/var/tmp": { - Path: "/var/tmp", - Mode: fs.ModeDir | 0777 | fs.ModeSticky, - Uid: 0, - Gid: 0, - OrigGroup: "group", - }, }, }, nil, @@ -307,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{ ".": { @@ -377,6 +378,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: change root", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -469,6 +471,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: change middle", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -559,6 +562,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: change leaf", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -645,6 +649,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: multiple changes", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -746,6 +751,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: absolute paths", + skipUnlessCiRun, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ "/": { @@ -780,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", @@ -831,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)