From 799f55e7ae6fa842c4bfe21513c406f830bca9a8 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 4 Mar 2014 22:17:28 +0100 Subject: [PATCH] Add basic config tests --- cmd/syncthing/config_test.go | 113 +++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 cmd/syncthing/config_test.go diff --git a/cmd/syncthing/config_test.go b/cmd/syncthing/config_test.go new file mode 100644 index 000000000..801d3d498 --- /dev/null +++ b/cmd/syncthing/config_test.go @@ -0,0 +1,113 @@ +package main + +import ( + "bytes" + "io" + "reflect" + "testing" +) + +func TestDefaultValues(t *testing.T) { + expected := OptionsConfiguration{ + ListenAddress: []string{":22000"}, + ReadOnly: false, + AllowDelete: true, + FollowSymlinks: true, + GUIEnabled: true, + GUIAddress: "127.0.0.1:8080", + GlobalAnnServer: "announce.syncthing.net:22025", + GlobalAnnEnabled: true, + LocalAnnEnabled: true, + ParallelRequests: 16, + MaxSendKbps: 0, + RescanIntervalS: 60, + ReconnectIntervalS: 60, + MaxChangeKbps: 1000, + } + + cfg, err := readConfigXML(bytes.NewReader(nil)) + if err != io.EOF { + t.Error(err) + } + + if !reflect.DeepEqual(cfg.Options, expected) { + t.Errorf("Default config differs;\n E: %#v\n A: %#v", expected, cfg.Options) + } +} + +func TestNoListenAddress(t *testing.T) { + data := []byte(` + + +
dynamic
+
+
+ + + +
+`) + + cfg, err := readConfigXML(bytes.NewReader(data)) + if err != nil { + t.Error(err) + } + + expected := []string{""} + if !reflect.DeepEqual(cfg.Options.ListenAddress, expected) { + t.Errorf("Unexpected ListenAddress %#v", cfg.Options.ListenAddress) + } +} + +func TestOverriddenValues(t *testing.T) { + data := []byte(` + + +
dynamic
+
+
+ + :23000 + true + false + false + false + 125.2.2.2:8080 + syncthing.nym.se:22025 + false + false + 32 + 1234 + 600 + 6000 + 2345 + +
+`) + + expected := OptionsConfiguration{ + ListenAddress: []string{":23000"}, + ReadOnly: true, + AllowDelete: false, + FollowSymlinks: false, + GUIEnabled: false, + GUIAddress: "125.2.2.2:8080", + GlobalAnnServer: "announce.nym.se:22025", + GlobalAnnEnabled: false, + LocalAnnEnabled: false, + ParallelRequests: 32, + MaxSendKbps: 1234, + RescanIntervalS: 600, + ReconnectIntervalS: 6000, + MaxChangeKbps: 2345, + } + + cfg, err := readConfigXML(bytes.NewReader(data)) + if err != nil { + t.Error(err) + } + + if !reflect.DeepEqual(cfg.Options, expected) { + t.Errorf("Overridden config differs;\n E: %#v\n A: %#v", expected, cfg.Options) + } +}