Browse code

fix openshift client cache for different versions

deads2k authored on 2015/11/11 00:34:43
Showing 2 changed files
... ...
@@ -489,6 +489,11 @@ func (c *clientCache) ClientConfigForVersion(version string) (*kclient.Config, e
489 489
 	client.SetOpenShiftDefaults(&config)
490 490
 	c.configs[version] = &config
491 491
 
492
+	// `version` does not necessarily equal `config.Version`.  However, we know that we call this method again with
493
+	// `config.Version`, we should get the the config we've just built.
494
+	configCopy := config
495
+	c.configs[config.Version] = &configCopy
496
+
492 497
 	return &config, nil
493 498
 }
494 499
 
... ...
@@ -32,7 +32,7 @@ func TestClientConfigForVersion(t *testing.T) {
32 32
 
33 33
 	// First call, negotiate
34 34
 	called = 0
35
-	v1Config, err := clients.ClientConfigForVersion("v1")
35
+	v1Config, err := clients.ClientConfigForVersion("")
36 36
 	if err != nil {
37 37
 		t.Fatalf("Unexpected error: %v", err)
38 38
 	}
... ...
@@ -45,6 +45,19 @@ func TestClientConfigForVersion(t *testing.T) {
45 45
 
46 46
 	// Second call, cache
47 47
 	called = 0
48
+	v1Config, err = clients.ClientConfigForVersion("")
49
+	if err != nil {
50
+		t.Fatalf("Unexpected error: %v", err)
51
+	}
52
+	if v1Config.Version != "v1" {
53
+		t.Fatalf("Expected v1, got %v", v1Config.Version)
54
+	}
55
+	if called != 0 {
56
+		t.Fatalf("Expected not be called again getting a config from cache, was called %d additional times", called)
57
+	}
58
+
59
+	// Third call, cached under exactly matching version
60
+	called = 0
48 61
 	v1Config, err = clients.ClientConfigForVersion("v1")
49 62
 	if err != nil {
50 63
 		t.Fatalf("Unexpected error: %v", err)