]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
config: forbid duplicate host names
authorSimon Ruderich <simon@ruderich.org>
Wed, 7 Apr 2021 17:11:45 +0000 (19:11 +0200)
committerSimon Ruderich <simon@ruderich.org>
Thu, 8 Apr 2021 16:53:44 +0000 (18:53 +0200)
cmd/safcm/config/hosts.go
cmd/safcm/config/hosts_test.go
cmd/safcm/testdata/host-invalid-duplicate/hosts.yaml [new file with mode: 0644]

index b3c4a24c65b1119bcf0ba8c87c72f691670c3e3c..823afa16c87aad2aa59aea79ff9ef34eeba2c3ae 100644 (file)
@@ -69,6 +69,10 @@ func LoadHosts() (*Hosts, error) {
                                errPrefix, GroupSpecialSeparator)
                }
 
+               if hostMap[x.Name] != nil {
+                       return nil, fmt.Errorf("%s host name already exists",
+                               errPrefix)
+               }
                hostMap[x.Name] = x
        }
 
index ecbc37e45314b7453864eb9d9d1cac22a57b4a53..5d3c3342955ec494bacec29c6a622a01e0332044 100644 (file)
@@ -64,6 +64,11 @@ func TestLoadHosts(t *testing.T) {
                        nil,
                },
 
+               {
+                       "../testdata/host-invalid-duplicate",
+                       nil,
+                       fmt.Errorf("hosts.yaml: host \"host1.example.org\": host name already exists"),
+               },
                {
                        "../testdata/host-invalid-all",
                        nil,
diff --git a/cmd/safcm/testdata/host-invalid-duplicate/hosts.yaml b/cmd/safcm/testdata/host-invalid-duplicate/hosts.yaml
new file mode 100644 (file)
index 0000000..d6670b0
--- /dev/null
@@ -0,0 +1,2 @@
+- name: host1.example.org
+- name: host1.example.org