X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm%2Fsync_test.go;h=4744ad553cd45715bcb08313842ad2700d5af800;hb=c899e17495d4eb932e0b4f428ec91882d845f1bc;hp=2e5b3ab95106710d84ff2bdcdbacdb891b22a0a7;hpb=3b727d74f76503b1306a81318025ed7772c884c3;p=safcm%2Fsafcm.git diff --git a/cmd/safcm/sync_test.go b/cmd/safcm/sync_test.go index 2e5b3ab..4744ad5 100644 --- a/cmd/safcm/sync_test.go +++ b/cmd/safcm/sync_test.go @@ -24,6 +24,7 @@ import ( "ruderich.org/simon/safcm" "ruderich.org/simon/safcm/cmd/safcm/config" + "ruderich.org/simon/safcm/frontend" "ruderich.org/simon/safcm/rpc" "ruderich.org/simon/safcm/testutil" ) @@ -44,6 +45,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 +111,7 @@ func TestHostsToSync(t *testing.T) { { "group: single name", - []string{"group"}, + []string{"group3"}, []*config.Host{ allHosts.Map["host1.example.org"], }, @@ -112,7 +119,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 +128,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 +137,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 +152,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"}, @@ -183,7 +203,7 @@ func TestLogEvent(t *testing.T) { tests := []struct { name string - event Event + event frontend.Event level safcm.LogLevel isTTY bool exp string @@ -192,7 +212,7 @@ func TestLogEvent(t *testing.T) { { "Error", - Event{ + frontend.Event{ Error: fmt.Errorf("fake error"), }, safcm.LogDebug3, @@ -202,7 +222,7 @@ func TestLogEvent(t *testing.T) { }, { "Error (tty)", - Event{ + frontend.Event{ Error: fmt.Errorf("fake error"), }, safcm.LogDebug3, @@ -212,7 +232,7 @@ func TestLogEvent(t *testing.T) { }, { "Error: escape", - Event{ + frontend.Event{ Error: fmt.Errorf("\x00"), }, safcm.LogDebug3, @@ -222,7 +242,7 @@ func TestLogEvent(t *testing.T) { }, { "Error: escape (tty)", - Event{ + frontend.Event{ Error: fmt.Errorf("\x00"), }, safcm.LogDebug3, @@ -233,8 +253,8 @@ func TestLogEvent(t *testing.T) { { "Log: info", - Event{ - Log: Log{ + frontend.Event{ + Log: frontend.Log{ Level: safcm.LogInfo, Text: "info log", }, @@ -246,8 +266,8 @@ func TestLogEvent(t *testing.T) { }, { "Log: info (tty)", - Event{ - Log: Log{ + frontend.Event{ + Log: frontend.Log{ Level: safcm.LogInfo, Text: "info log", }, @@ -259,8 +279,8 @@ func TestLogEvent(t *testing.T) { }, { "Log: verbose", - Event{ - Log: Log{ + frontend.Event{ + Log: frontend.Log{ Level: safcm.LogVerbose, Text: "verbose log", }, @@ -272,8 +292,8 @@ func TestLogEvent(t *testing.T) { }, { "Log: debug", - Event{ - Log: Log{ + frontend.Event{ + Log: frontend.Log{ Level: safcm.LogDebug, Text: "debug log", }, @@ -285,8 +305,8 @@ func TestLogEvent(t *testing.T) { }, { "Log: debug2", - Event{ - Log: Log{ + frontend.Event{ + Log: frontend.Log{ Level: safcm.LogDebug2, Text: "debug2 log", }, @@ -298,8 +318,8 @@ func TestLogEvent(t *testing.T) { }, { "Log: debug3", - Event{ - Log: Log{ + frontend.Event{ + Log: frontend.Log{ Level: safcm.LogDebug3, Text: "debug3 log", }, @@ -312,8 +332,8 @@ func TestLogEvent(t *testing.T) { }, { "Log: debug3 (tty)", - Event{ - Log: Log{ + frontend.Event{ + Log: frontend.Log{ Level: safcm.LogDebug3, Text: "debug3 log", }, @@ -326,8 +346,8 @@ func TestLogEvent(t *testing.T) { }, { "Log: escape", - Event{ - Log: Log{ + frontend.Event{ + Log: frontend.Log{ Level: safcm.LogInfo, Text: "\x00", }, @@ -339,8 +359,8 @@ func TestLogEvent(t *testing.T) { }, { "Log: escape (tty)", - Event{ - Log: Log{ + frontend.Event{ + Log: frontend.Log{ Level: safcm.LogInfo, Text: "\x00", }, @@ -353,7 +373,7 @@ func TestLogEvent(t *testing.T) { { "ConnEvent: stderr", - Event{ + frontend.Event{ ConnEvent: rpc.ConnEvent{ Type: rpc.ConnEventStderr, Data: "fake stderr", @@ -366,7 +386,7 @@ func TestLogEvent(t *testing.T) { }, { "ConnEvent: stderr (tty)", - Event{ + frontend.Event{ ConnEvent: rpc.ConnEvent{ Type: rpc.ConnEventStderr, Data: "fake stderr", @@ -379,7 +399,7 @@ func TestLogEvent(t *testing.T) { }, { "ConnEvent: debug", - Event{ + frontend.Event{ ConnEvent: rpc.ConnEvent{ Type: rpc.ConnEventDebug, Data: "conn debug", @@ -392,7 +412,7 @@ func TestLogEvent(t *testing.T) { }, { "ConnEvent: upload", - Event{ + frontend.Event{ ConnEvent: rpc.ConnEvent{ Type: rpc.ConnEventUpload, }, @@ -404,7 +424,7 @@ func TestLogEvent(t *testing.T) { }, { "ConnEvent: upload (ignored)", - Event{ + frontend.Event{ ConnEvent: rpc.ConnEvent{ Type: rpc.ConnEventUpload, }, @@ -416,7 +436,7 @@ func TestLogEvent(t *testing.T) { }, { "ConnEvent: invalid", - Event{ + frontend.Event{ ConnEvent: rpc.ConnEvent{ Type: 42, Data: "invalid", @@ -429,7 +449,7 @@ func TestLogEvent(t *testing.T) { }, { "ConnEvent: invalid (tty)", - Event{ + frontend.Event{ ConnEvent: rpc.ConnEvent{ Type: 42, Data: "invalid", @@ -442,7 +462,7 @@ func TestLogEvent(t *testing.T) { }, { "ConnEvent: escape", - Event{ + frontend.Event{ ConnEvent: rpc.ConnEvent{ Type: rpc.ConnEventStderr, Data: "\x00", @@ -455,7 +475,7 @@ func TestLogEvent(t *testing.T) { }, { "ConnEvent: escape (tty)", - Event{ + frontend.Event{ ConnEvent: rpc.ConnEvent{ Type: rpc.ConnEventDebug, Data: "\x01", @@ -469,8 +489,8 @@ func TestLogEvent(t *testing.T) { { "Escaped", - Event{ - Log: Log{ + frontend.Event{ + Log: frontend.Log{ Level: safcm.LogInfo, Text: "\x00", }, @@ -483,8 +503,8 @@ func TestLogEvent(t *testing.T) { }, { "Escaped (tty)", - Event{ - Log: Log{ + frontend.Event{ + Log: frontend.Log{ Level: safcm.LogInfo, Text: "\x00", }, @@ -498,7 +518,7 @@ func TestLogEvent(t *testing.T) { { "empty (invalid)", - Event{}, + frontend.Event{}, safcm.LogDebug3, false, "[INVALID=0] [fake-host] \n", @@ -508,8 +528,10 @@ func TestLogEvent(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { - tc.event.Host = &config.Host{ - Name: "fake-host", + tc.event.Host = &Sync{ + host: &config.Host{ + Name: "fake-host", + }, } var buf bytes.Buffer