This is especially important in case the user executes the tests as root
(no recommended but not prevented either). Permissions on paths like /
or /tmp which differ from those expected by the test could otherwise be
modified by the tests.
However, the end-to-end SSH tests which write /tmp/safcm-remote-$uid
(but no other paths) are still run so we get proper coverage of basic
features.
+# Run additional tests in CI
+SAFCM_CI_RUN=1
+export SAFCM_CI_RUN
+
make $flags
make test $flags
make $flags
make test $flags
}
user, uid, group, gid := ft.CurrentUserAndGroup()
}
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
tmpTestFilePath := "/tmp/safcm-sync-files-test-file"
tests := []struct {
name string
req safcm.MsgSyncReq
prepare func()
triggers []string
req safcm.MsgSyncReq
prepare func()
triggers []string
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
},
{
"invalid File: group",
},
{
"invalid File: group",
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
// Use numeric IDs as not all systems use root/root;
// for example BSDs use root/wheel.
"absolute paths: no change",
// Use numeric IDs as not all systems use root/root;
// for example BSDs use root/wheel.
"absolute paths: no change",
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
"/": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
"/": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
{
"triggers: change root",
{
"triggers: change root",
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
{
"triggers: change middle",
{
"triggers: change middle",
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
{
"triggers: change leaf",
{
"triggers: change leaf",
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
{
"triggers: multiple changes",
{
"triggers: multiple changes",
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
".": {
{
"triggers: absolute paths",
{
"triggers: absolute paths",
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
"/": {
safcm.MsgSyncReq{
Files: map[string]*safcm.File{
"/": {
- 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)
- }
- },
for _, tc := range tests {
t.Run(tc.name, func(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)
// Create separate test directory for each test case
path := filepath.Join(cwd, "testdata", "files-"+tc.name)
err = os.Mkdir(path, 0700)