X-Git-Url: https://ruderich.org/simon/gitweb/?p=safcm%2Fsafcm.git;a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fsync%2Ffiles_test.go;h=bd5eac9930c31b8978efe8060f491dd859b9d604;hp=879fefda156b8789d6b0818459a05b15eb3aa9ae;hb=e4c6a178848145c8dba68ed054cbb48dcecccf65;hpb=8bf2ac237af2faacd963485696c499c46b5a11e5 diff --git a/cmd/safcm-remote/sync/files_test.go b/cmd/safcm-remote/sync/files_test.go index 879fefd..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{ "/": { @@ -306,6 +314,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: no change", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -369,6 +378,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: change root", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -461,6 +471,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: change middle", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -551,6 +562,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: change leaf", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -637,6 +649,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: multiple changes", + false, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ ".": { @@ -738,6 +751,7 @@ func TestSyncFiles(t *testing.T) { { "triggers: absolute paths", + skipUnlessCiRun, safcm.MsgSyncReq{ Files: map[string]*safcm.File{ "/": { @@ -772,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", @@ -823,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)