]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - cmd/safcm/sync_test.go
safcm: forbid syncing groups which depend on "detected" groups
[safcm/safcm.git] / cmd / safcm / sync_test.go
index 2e5b3ab95106710d84ff2bdcdbacdb891b22a0a7..80b1589072ace73792c3bd51723b02320d996c61 100644 (file)
@@ -44,6 +44,12 @@ func TestHostsToSync(t *testing.T) {
                t.Fatal(err)
        }
 
+       const errMsg = `
+
+Groups depending on "detected" groups cannot be used to select hosts as these
+are only available after the hosts were contacted.
+`
+
        tests := []struct {
                name   string
                names  []string
@@ -104,7 +110,7 @@ func TestHostsToSync(t *testing.T) {
 
                {
                        "group: single name",
-                       []string{"group"},
+                       []string{"group3"},
                        []*config.Host{
                                allHosts.Map["host1.example.org"],
                        },
@@ -112,7 +118,7 @@ func TestHostsToSync(t *testing.T) {
                },
                {
                        "group: multiple names",
-                       []string{"group", "group2"},
+                       []string{"group3", "group2"},
                        []*config.Host{
                                allHosts.Map["host1.example.org"],
                                allHosts.Map["host2"],
@@ -121,7 +127,7 @@ func TestHostsToSync(t *testing.T) {
                },
                {
                        "group: multiple identical names",
-                       []string{"group", "group2", "group"},
+                       []string{"group3", "group2", "group3"},
                        []*config.Host{
                                allHosts.Map["host1.example.org"],
                                allHosts.Map["host2"],
@@ -130,7 +136,7 @@ func TestHostsToSync(t *testing.T) {
                },
                {
                        "group: multiple names, including unknown",
-                       []string{"group", "group2", "unknown-group"},
+                       []string{"group3", "group2", "unknown-group"},
                        nil,
                        fmt.Errorf("hosts/groups not found: \"unknown-group\""),
                },
@@ -145,6 +151,19 @@ func TestHostsToSync(t *testing.T) {
                        nil,
                },
 
+               {
+                       "group: single name (detected)",
+                       []string{"group"},
+                       nil,
+                       fmt.Errorf(`group "group" depends on "detected" groups` + errMsg),
+               },
+               {
+                       "group: multiple names (detected)",
+                       []string{"group", "group2"},
+                       nil,
+                       fmt.Errorf(`group "group" depends on "detected" groups` + errMsg),
+               },
+
                {
                        "\"all\" and name",
                        []string{"all", "group2"},