2014-07-12 15:45:33 -07:00
|
|
|
// 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.
|
2014-06-01 13:50:14 -07:00
|
|
|
|
2014-05-14 17:18:09 -07:00
|
|
|
package config
|
2014-03-04 14:17:28 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
2014-04-22 03:06:32 -07:00
|
|
|
"os"
|
2014-03-04 14:17:28 -07:00
|
|
|
"reflect"
|
|
|
|
"testing"
|
2014-06-06 20:10:15 -07:00
|
|
|
|
2014-08-01 07:35:37 -07:00
|
|
|
"github.com/syncthing/syncthing/protocol"
|
2014-03-04 14:17:28 -07:00
|
|
|
)
|
|
|
|
|
2014-06-29 16:42:03 -07:00
|
|
|
var node1, node2, node3, node4 protocol.NodeID
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
node1, _ = protocol.NodeIDFromString("AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ")
|
|
|
|
node2, _ = protocol.NodeIDFromString("GYRZZQB-IRNPV4Z-T7TC52W-EQYJ3TT-FDQW6MW-DFLMU42-SSSU6EM-FBK2VAY")
|
|
|
|
node3, _ = protocol.NodeIDFromString("LGFPDIT-7SKNNJL-VJZA4FC-7QNCRKA-CE753K7-2BW5QDK-2FOZ7FR-FEP57QJ")
|
|
|
|
node4, _ = protocol.NodeIDFromString("P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2")
|
|
|
|
}
|
|
|
|
|
2014-03-04 14:17:28 -07:00
|
|
|
func TestDefaultValues(t *testing.T) {
|
|
|
|
expected := OptionsConfiguration{
|
2014-05-14 08:43:49 -07:00
|
|
|
ListenAddress: []string{"0.0.0.0:22000"},
|
2014-07-13 12:07:04 -07:00
|
|
|
GlobalAnnServer: "announce.syncthing.net:22026",
|
2014-03-04 14:17:28 -07:00
|
|
|
GlobalAnnEnabled: true,
|
|
|
|
LocalAnnEnabled: true,
|
2014-05-22 00:35:54 -07:00
|
|
|
LocalAnnPort: 21025,
|
2014-08-17 06:01:48 -07:00
|
|
|
LocalAnnMCAddr: "[ff32::5222]:21026",
|
2014-03-04 14:17:28 -07:00
|
|
|
ParallelRequests: 16,
|
|
|
|
MaxSendKbps: 0,
|
|
|
|
ReconnectIntervalS: 60,
|
2014-03-08 15:19:33 -07:00
|
|
|
StartBrowser: true,
|
2014-04-18 04:39:51 -07:00
|
|
|
UPnPEnabled: true,
|
2014-08-14 03:59:09 -07:00
|
|
|
UPnPLease: 0,
|
|
|
|
UPnPRenewal: 30,
|
2014-03-04 14:17:28 -07:00
|
|
|
}
|
|
|
|
|
2014-06-29 16:42:03 -07:00
|
|
|
cfg, err := Load(bytes.NewReader(nil), node1)
|
2014-03-04 14:17:28 -07:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-08 04:45:18 -07:00
|
|
|
func TestNodeConfig(t *testing.T) {
|
|
|
|
v1data := []byte(`
|
|
|
|
<configuration version="1">
|
|
|
|
<repository id="test" directory="~/Sync">
|
2014-06-29 16:42:03 -07:00
|
|
|
<node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ" name="node one">
|
2014-04-08 04:45:18 -07:00
|
|
|
<address>a</address>
|
|
|
|
</node>
|
2014-06-29 16:42:03 -07:00
|
|
|
<node id="P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ" name="node two">
|
2014-04-08 04:45:18 -07:00
|
|
|
<address>b</address>
|
|
|
|
</node>
|
2014-07-27 16:15:16 -07:00
|
|
|
<node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ" name="node one">
|
|
|
|
<address>a</address>
|
|
|
|
</node>
|
|
|
|
<node id="P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ" name="node two">
|
|
|
|
<address>b</address>
|
|
|
|
</node>
|
2014-04-08 04:45:18 -07:00
|
|
|
</repository>
|
|
|
|
<options>
|
|
|
|
<readOnly>true</readOnly>
|
2014-08-18 14:05:47 -07:00
|
|
|
<rescanIntervalS>600</rescanIntervalS>
|
2014-04-08 04:45:18 -07:00
|
|
|
</options>
|
|
|
|
</configuration>
|
|
|
|
`)
|
|
|
|
|
|
|
|
v2data := []byte(`
|
|
|
|
<configuration version="2">
|
|
|
|
<repository id="test" directory="~/Sync" ro="true">
|
2014-07-27 16:15:16 -07:00
|
|
|
<node id="P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ"/>
|
2014-06-29 16:42:03 -07:00
|
|
|
<node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ"/>
|
2014-07-22 14:27:00 -07:00
|
|
|
<node id="C4YBIESWDUAIGU62GOSRXCRAAJDWVE3TKCPMURZE2LH5QHAF576A"/>
|
2014-06-29 16:42:03 -07:00
|
|
|
<node id="P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ"/>
|
2014-07-27 16:15:16 -07:00
|
|
|
<node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ"/>
|
|
|
|
<node id="C4YBIESWDUAIGU62GOSRXCRAAJDWVE3TKCPMURZE2LH5QHAF576A"/>
|
2014-04-08 04:45:18 -07:00
|
|
|
</repository>
|
2014-06-29 16:42:03 -07:00
|
|
|
<node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ" name="node one">
|
2014-04-08 04:45:18 -07:00
|
|
|
<address>a</address>
|
|
|
|
</node>
|
2014-06-29 16:42:03 -07:00
|
|
|
<node id="P56IOI7MZJNU2IQGDREYDM2MGTMGL3BXNPQ6W5BTBBZ4TJXZWICQ" name="node two">
|
2014-04-08 04:45:18 -07:00
|
|
|
<address>b</address>
|
|
|
|
</node>
|
2014-08-18 14:05:47 -07:00
|
|
|
<options>
|
|
|
|
<rescanIntervalS>600</rescanIntervalS>
|
|
|
|
</options>
|
2014-04-08 04:45:18 -07:00
|
|
|
</configuration>
|
|
|
|
`)
|
|
|
|
|
2014-08-01 07:48:06 -07:00
|
|
|
v3data := []byte(`
|
|
|
|
<configuration version="3">
|
|
|
|
<repository id="test" directory="~/Sync" ro="true" ignorePerms="false">
|
|
|
|
<node id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR" compression="false"></node>
|
|
|
|
<node id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2" compression="false"></node>
|
|
|
|
</repository>
|
|
|
|
<node id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR" name="node one" compression="true">
|
|
|
|
<address>a</address>
|
|
|
|
</node>
|
|
|
|
<node id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2" name="node two" compression="true">
|
|
|
|
<address>b</address>
|
|
|
|
</node>
|
2014-08-18 14:05:47 -07:00
|
|
|
<options>
|
|
|
|
<rescanIntervalS>600</rescanIntervalS>
|
|
|
|
</options>
|
2014-08-01 07:48:06 -07:00
|
|
|
</configuration>`)
|
|
|
|
|
2014-08-16 15:20:21 -07:00
|
|
|
v4data := []byte(`
|
|
|
|
<configuration version="4">
|
2014-08-18 14:05:47 -07:00
|
|
|
<repository id="test" directory="~/Sync" ro="true" ignorePerms="false" rescanIntervalS="600">
|
2014-08-16 15:20:21 -07:00
|
|
|
<node id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR"></node>
|
|
|
|
<node id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2"></node>
|
|
|
|
</repository>
|
|
|
|
<node id="AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR" name="node one" compression="true">
|
|
|
|
<address>a</address>
|
|
|
|
</node>
|
|
|
|
<node id="P56IOI7-MZJNU2Y-IQGDREY-DM2MGTI-MGL3BXN-PQ6W5BM-TBBZ4TJ-XZWICQ2" name="node two" compression="true">
|
|
|
|
<address>b</address>
|
|
|
|
</node>
|
|
|
|
</configuration>`)
|
|
|
|
|
|
|
|
for i, data := range [][]byte{v1data, v2data, v3data, v4data} {
|
2014-06-29 16:42:03 -07:00
|
|
|
cfg, err := Load(bytes.NewReader(data), node1)
|
2014-04-08 04:45:18 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedRepos := []RepositoryConfiguration{
|
|
|
|
{
|
2014-08-18 14:05:47 -07:00
|
|
|
ID: "test",
|
|
|
|
Directory: "~/Sync",
|
|
|
|
Nodes: []RepositoryNodeConfiguration{{NodeID: node1}, {NodeID: node4}},
|
|
|
|
ReadOnly: true,
|
|
|
|
RescanIntervalS: 600,
|
2014-04-08 04:45:18 -07:00
|
|
|
},
|
|
|
|
}
|
|
|
|
expectedNodes := []NodeConfiguration{
|
|
|
|
{
|
2014-08-01 07:48:06 -07:00
|
|
|
NodeID: node1,
|
|
|
|
Name: "node one",
|
|
|
|
Addresses: []string{"a"},
|
|
|
|
Compression: true,
|
2014-04-08 04:45:18 -07:00
|
|
|
},
|
|
|
|
{
|
2014-08-01 07:48:06 -07:00
|
|
|
NodeID: node4,
|
|
|
|
Name: "node two",
|
|
|
|
Addresses: []string{"b"},
|
|
|
|
Compression: true,
|
2014-04-08 04:45:18 -07:00
|
|
|
},
|
|
|
|
}
|
2014-06-29 16:42:03 -07:00
|
|
|
expectedNodeIDs := []protocol.NodeID{node1, node4}
|
2014-04-08 04:45:18 -07:00
|
|
|
|
2014-08-16 15:20:21 -07:00
|
|
|
if cfg.Version != 4 {
|
2014-08-01 07:48:06 -07:00
|
|
|
t.Errorf("%d: Incorrect version %d != 3", i, cfg.Version)
|
2014-04-08 04:45:18 -07:00
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(cfg.Repositories, expectedRepos) {
|
|
|
|
t.Errorf("%d: Incorrect Repositories\n A: %#v\n E: %#v", i, cfg.Repositories, expectedRepos)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(cfg.Nodes, expectedNodes) {
|
|
|
|
t.Errorf("%d: Incorrect Nodes\n A: %#v\n E: %#v", i, cfg.Nodes, expectedNodes)
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
}
|
2014-07-31 05:13:55 -07:00
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
2014-04-08 04:45:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-04 14:17:28 -07:00
|
|
|
func TestNoListenAddress(t *testing.T) {
|
|
|
|
data := []byte(`<configuration version="1">
|
|
|
|
<options>
|
|
|
|
<listenAddress></listenAddress>
|
|
|
|
</options>
|
|
|
|
</configuration>
|
|
|
|
`)
|
|
|
|
|
2014-06-29 16:42:03 -07:00
|
|
|
cfg, err := Load(bytes.NewReader(data), node1)
|
2014-03-04 14:17:28 -07:00
|
|
|
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) {
|
2014-04-08 04:45:18 -07:00
|
|
|
data := []byte(`<configuration version="2">
|
2014-03-04 14:17:28 -07:00
|
|
|
<options>
|
|
|
|
<listenAddress>:23000</listenAddress>
|
|
|
|
<allowDelete>false</allowDelete>
|
2014-07-13 12:07:04 -07:00
|
|
|
<globalAnnounceServer>syncthing.nym.se:22026</globalAnnounceServer>
|
2014-03-04 14:17:28 -07:00
|
|
|
<globalAnnounceEnabled>false</globalAnnounceEnabled>
|
|
|
|
<localAnnounceEnabled>false</localAnnounceEnabled>
|
2014-05-22 00:35:54 -07:00
|
|
|
<localAnnouncePort>42123</localAnnouncePort>
|
2014-08-17 06:01:48 -07:00
|
|
|
<localAnnounceMCAddr>quux:3232</localAnnounceMCAddr>
|
2014-03-04 14:17:28 -07:00
|
|
|
<parallelRequests>32</parallelRequests>
|
|
|
|
<maxSendKbps>1234</maxSendKbps>
|
|
|
|
<reconnectionIntervalS>6000</reconnectionIntervalS>
|
2014-03-08 15:19:33 -07:00
|
|
|
<startBrowser>false</startBrowser>
|
2014-04-18 04:39:51 -07:00
|
|
|
<upnpEnabled>false</upnpEnabled>
|
2014-08-14 03:59:09 -07:00
|
|
|
<upnpLeaseMinutes>60</upnpLeaseMinutes>
|
|
|
|
<upnpRenewalMinutes>15</upnpRenewalMinutes>
|
2014-03-04 14:17:28 -07:00
|
|
|
</options>
|
|
|
|
</configuration>
|
|
|
|
`)
|
|
|
|
|
|
|
|
expected := OptionsConfiguration{
|
|
|
|
ListenAddress: []string{":23000"},
|
2014-07-13 12:07:04 -07:00
|
|
|
GlobalAnnServer: "syncthing.nym.se:22026",
|
2014-03-04 14:17:28 -07:00
|
|
|
GlobalAnnEnabled: false,
|
|
|
|
LocalAnnEnabled: false,
|
2014-05-22 00:35:54 -07:00
|
|
|
LocalAnnPort: 42123,
|
2014-08-17 06:01:48 -07:00
|
|
|
LocalAnnMCAddr: "quux:3232",
|
2014-03-04 14:17:28 -07:00
|
|
|
ParallelRequests: 32,
|
|
|
|
MaxSendKbps: 1234,
|
|
|
|
ReconnectIntervalS: 6000,
|
2014-03-08 15:19:33 -07:00
|
|
|
StartBrowser: false,
|
2014-04-18 04:39:51 -07:00
|
|
|
UPnPEnabled: false,
|
2014-08-14 03:59:09 -07:00
|
|
|
UPnPLease: 60,
|
|
|
|
UPnPRenewal: 15,
|
2014-03-04 14:17:28 -07:00
|
|
|
}
|
|
|
|
|
2014-06-29 16:42:03 -07:00
|
|
|
cfg, err := Load(bytes.NewReader(data), node1)
|
2014-03-04 14:17:28 -07:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2014-04-22 02:46:08 -07:00
|
|
|
|
2014-07-24 04:23:17 -07:00
|
|
|
func TestNodeAddressesDynamic(t *testing.T) {
|
2014-04-22 02:46:08 -07:00
|
|
|
data := []byte(`
|
|
|
|
<configuration version="2">
|
2014-06-29 16:42:03 -07:00
|
|
|
<node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ">
|
2014-04-22 02:46:08 -07:00
|
|
|
<address></address>
|
|
|
|
</node>
|
2014-06-29 16:42:03 -07:00
|
|
|
<node id="GYRZZQBIRNPV4T7TC52WEQYJ3TFDQW6MWDFLMU4SSSU6EMFBK2VA">
|
|
|
|
</node>
|
|
|
|
<node id="LGFPDIT7SKNNJVJZA4FC7QNCRKCE753K72BW5QD2FOZ7FRFEP57Q">
|
|
|
|
<address>dynamic</address>
|
2014-04-22 02:46:08 -07:00
|
|
|
</node>
|
|
|
|
</configuration>
|
|
|
|
`)
|
|
|
|
|
2014-04-22 03:06:32 -07:00
|
|
|
name, _ := os.Hostname()
|
2014-04-22 02:46:08 -07:00
|
|
|
expected := []NodeConfiguration{
|
|
|
|
{
|
2014-08-01 07:48:06 -07:00
|
|
|
NodeID: node1,
|
|
|
|
Addresses: []string{"dynamic"},
|
|
|
|
Compression: true,
|
2014-04-22 02:46:08 -07:00
|
|
|
},
|
|
|
|
{
|
2014-08-01 07:48:06 -07:00
|
|
|
NodeID: node2,
|
|
|
|
Addresses: []string{"dynamic"},
|
|
|
|
Compression: true,
|
2014-04-22 02:46:08 -07:00
|
|
|
},
|
|
|
|
{
|
2014-08-01 07:48:06 -07:00
|
|
|
NodeID: node3,
|
|
|
|
Addresses: []string{"dynamic"},
|
|
|
|
Compression: true,
|
2014-04-22 02:46:08 -07:00
|
|
|
},
|
|
|
|
{
|
2014-06-29 16:42:03 -07:00
|
|
|
NodeID: node4,
|
2014-04-22 03:06:32 -07:00
|
|
|
Name: name, // Set when auto created
|
2014-04-22 02:46:08 -07:00
|
|
|
Addresses: []string{"dynamic"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2014-06-29 16:42:03 -07:00
|
|
|
cfg, err := Load(bytes.NewReader(data), node4)
|
2014-04-22 02:46:08 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(cfg.Nodes, expected) {
|
|
|
|
t.Errorf("Nodes differ;\n E: %#v\n A: %#v", expected, cfg.Nodes)
|
|
|
|
}
|
|
|
|
}
|
2014-07-24 04:23:17 -07:00
|
|
|
|
|
|
|
func TestNodeAddressesStatic(t *testing.T) {
|
|
|
|
data := []byte(`
|
2014-08-01 07:48:06 -07:00
|
|
|
<configuration version="3">
|
2014-07-24 04:23:17 -07:00
|
|
|
<node id="AIR6LPZ7K4PTTUXQSMUUCPQ5YWOEDFIIQJUG7772YQXXR5YD6AWQ">
|
|
|
|
<address>192.0.2.1</address>
|
|
|
|
<address>192.0.2.2</address>
|
|
|
|
</node>
|
|
|
|
<node id="GYRZZQBIRNPV4T7TC52WEQYJ3TFDQW6MWDFLMU4SSSU6EMFBK2VA">
|
|
|
|
<address>192.0.2.3:6070</address>
|
|
|
|
<address>[2001:db8::42]:4242</address>
|
|
|
|
</node>
|
|
|
|
<node id="LGFPDIT7SKNNJVJZA4FC7QNCRKCE753K72BW5QD2FOZ7FRFEP57Q">
|
|
|
|
<address>[2001:db8::44]:4444</address>
|
|
|
|
<address>192.0.2.4:6090</address>
|
|
|
|
</node>
|
|
|
|
</configuration>
|
|
|
|
`)
|
|
|
|
|
|
|
|
name, _ := os.Hostname()
|
|
|
|
expected := []NodeConfiguration{
|
|
|
|
{
|
|
|
|
NodeID: node1,
|
|
|
|
Addresses: []string{"192.0.2.1", "192.0.2.2"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NodeID: node2,
|
|
|
|
Addresses: []string{"192.0.2.3:6070", "[2001:db8::42]:4242"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NodeID: node3,
|
|
|
|
Addresses: []string{"[2001:db8::44]:4444", "192.0.2.4:6090"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
NodeID: node4,
|
|
|
|
Name: name, // Set when auto created
|
|
|
|
Addresses: []string{"dynamic"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg, err := Load(bytes.NewReader(data), node4)
|
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(cfg.Nodes, expected) {
|
|
|
|
t.Errorf("Nodes differ;\n E: %#v\n A: %#v", expected, cfg.Nodes)
|
|
|
|
}
|
|
|
|
}
|
2014-07-31 05:13:55 -07:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|