Browse code

Fix `--cluster-store` option parser

`--cluster-store` is of form KV-PROVIDER://KV-URL, this commit makes
sure that KV-URL contains no "://"

Signed-off-by: Zhang Wei <zhangwei555@huawei.com>

Zhang Wei authored on 2015/11/04 23:27:23
Showing 2 changed files
... ...
@@ -549,3 +549,28 @@ func TestParseSecurityOpt(t *testing.T) {
549 549
 		t.Fatal("Expected parseSecurityOpt error, got nil")
550 550
 	}
551 551
 }
552
+
553
+func TestNetworkOptions(t *testing.T) {
554
+	daemon := &Daemon{}
555
+	dconfigCorrect := &Config{
556
+		CommonConfig: CommonConfig{
557
+			DefaultNetwork:   "netPlugin:mynet:dev",
558
+			ClusterStore:     "consul://localhost:8500",
559
+			ClusterAdvertise: "192.168.0.1:8000",
560
+		},
561
+	}
562
+
563
+	if _, err := daemon.networkOptions(dconfigCorrect); err != nil {
564
+		t.Fatalf("Expect networkOptions sucess, got error: %v", err)
565
+	}
566
+
567
+	dconfigWrong := &Config{
568
+		CommonConfig: CommonConfig{
569
+			ClusterStore: "consul://localhost:8500://test://bbb",
570
+		},
571
+	}
572
+
573
+	if _, err := daemon.networkOptions(dconfigWrong); err == nil {
574
+		t.Fatalf("Expected networkOptions error, got nil")
575
+	}
576
+}
... ...
@@ -333,11 +333,11 @@ func (daemon *Daemon) networkOptions(dconfig *Config) ([]nwconfig.Option, error)
333 333
 
334 334
 	if strings.TrimSpace(dconfig.ClusterStore) != "" {
335 335
 		kv := strings.Split(dconfig.ClusterStore, "://")
336
-		if len(kv) < 2 {
336
+		if len(kv) != 2 {
337 337
 			return nil, fmt.Errorf("kv store daemon config must be of the form KV-PROVIDER://KV-URL")
338 338
 		}
339 339
 		options = append(options, nwconfig.OptionKVProvider(kv[0]))
340
-		options = append(options, nwconfig.OptionKVProviderURL(strings.Join(kv[1:], "://")))
340
+		options = append(options, nwconfig.OptionKVProviderURL(kv[1]))
341 341
 	}
342 342
 	if len(dconfig.ClusterOpts) > 0 {
343 343
 		options = append(options, nwconfig.OptionKVOpts(dconfig.ClusterOpts))