-// Copyright (C) 2021 Simon Ruderich
+// Copyright (C) 2021-2023 Simon Ruderich
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
if err != nil {
t.Fatal(err)
}
- defer os.Chdir(cwd)
+ defer os.Chdir(cwd) //nolint:errcheck
err = os.Chdir("testdata/project")
if err != nil {
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
{
"group: single name",
- []string{"group"},
+ []string{"group3"},
[]*config.Host{
allHosts.Map["host1.example.org"],
},
},
{
"group: multiple names",
- []string{"group", "group2"},
+ []string{"group3", "group2"},
[]*config.Host{
allHosts.Map["host1.example.org"],
allHosts.Map["host2"],
},
{
"group: multiple identical names",
- []string{"group", "group2", "group"},
+ []string{"group3", "group2", "group3"},
[]*config.Host{
allHosts.Map["host1.example.org"],
allHosts.Map["host2"],
},
{
"group: multiple names, including unknown",
- []string{"group", "group2", "unknown-group"},
+ []string{"group3", "group2", "unknown-group"},
nil,
fmt.Errorf("hosts/groups not found: \"unknown-group\""),
},
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"},