Просмотр исходного кода

Test maps and versioning config

Jakob Borg 11 лет назад
Родитель
Сommit
244f0ffaf1
2 измененных файлов с 45 добавлено и 0 удалено
  1. 4 0
      beacon/beacon_test.go
  2. 41 0
      config/config_test.go

+ 4 - 0
beacon/beacon_test.go

@@ -1,3 +1,7 @@
+// Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
+// All rights reserved. Use of this source code is governed by an MIT-style
+// license that can be found in the LICENSE file.
+
 package beacon
 
 import (

+ 41 - 0
config/config_test.go

@@ -131,6 +131,13 @@ func TestNodeConfig(t *testing.T) {
 		if !reflect.DeepEqual(cfg.Repositories[0].NodeIDs(), expectedNodeIDs) {
 			t.Errorf("%d: Incorrect NodeIDs\n  A: %#v\n  E: %#v", i, cfg.Repositories[0].NodeIDs(), expectedNodeIDs)
 		}
+
+		if len(cfg.NodeMap()) != len(expectedNodes) {
+			t.Errorf("Unexpected number of NodeMap() entries")
+		}
+		if len(cfg.RepoMap()) != len(expectedRepos) {
+			t.Errorf("Unexpected number of RepoMap() entries")
+		}
 	}
 }
 
@@ -291,3 +298,37 @@ func TestNodeAddressesStatic(t *testing.T) {
 		t.Errorf("Nodes differ;\n  E: %#v\n  A: %#v", expected, cfg.Nodes)
 	}
 }
+
+func TestVersioningConfig(t *testing.T) {
+	data := []byte(`
+		<configuration version="2">
+			<repository id="test" directory="~/Sync" ro="true">
+				<versioning type="simple">
+					<param key="foo" val="bar"/>
+					<param key="baz" val="quux"/>
+				</versioning>
+			</repository>
+		</configuration>
+		`)
+
+	cfg, err := Load(bytes.NewReader(data), node4)
+	if err != nil {
+		t.Error(err)
+	}
+
+	vc := cfg.Repositories[0].Versioning
+	if vc.Type != "simple" {
+		t.Errorf(`vc.Type %q != "simple"`, vc.Type)
+	}
+	if l := len(vc.Params); l != 2 {
+		t.Errorf("len(vc.Params) %d != 2", l)
+	}
+
+	expected := map[string]string{
+		"foo": "bar",
+		"baz": "quux",
+	}
+	if !reflect.DeepEqual(vc.Params, expected) {
+		t.Errorf("vc.Params differ;\n  E: %#v\n  A: %#v", expected, vc.Params)
+	}
+}