Browse code

Fixed bug in getClientAndPath

Michal Fojtik authored on 2014/09/12 20:38:47
Showing 2 changed files
... ...
@@ -55,7 +55,7 @@ func Apply(data []byte, storage clientapi.ClientMappings) (errs errors.ErrorList
55 55
 // kind.
56 56
 func getClientAndPath(kind string, mappings clientapi.ClientMappings) (client clientapi.RESTClient, path string) {
57 57
 	for k, m := range mappings {
58
-		if k == kind {
58
+		if m.Kind == kind {
59 59
 			return m.Client, k
60 60
 		}
61 61
 	}
... ...
@@ -28,12 +28,8 @@ func TestParseKindAndItem(t *testing.T) {
28 28
 }
29 29
 
30 30
 func TestApply(t *testing.T) {
31
-	invalidData := []byte(`{"items": [ { "foo": "bar" } ]}`)
32
-	invalidConf := configJSON{}
33
-	if err := json.Unmarshal(invalidData, &invalidConf); err != nil {
34
-		t.Errorf("Failed to parse Config: %v", err)
35
-	}
36 31
 	clients := clientapi.ClientMappings{}
32
+	invalidData := []byte(`{"items": [ { "foo": "bar" } ]}`)
37 33
 	errs := Apply(invalidData, clients)
38 34
 	if len(errs) == 0 {
39 35
 		t.Errorf("Expected missing kind field for Config item, got %v", errs)
... ...
@@ -44,22 +40,30 @@ func TestApply(t *testing.T) {
44 44
 	}
45 45
 }
46 46
 
47
+func TestGetClientAndPath(t *testing.T) {
48
+	kubeClient, _ := kubeclient.New("127.0.0.1", nil)
49
+	testClientMappings := clientapi.ClientMappings{
50
+		"pods":     {"Pod", kubeClient.RESTClient},
51
+		"services": {"Service", kubeClient.RESTClient},
52
+	}
53
+	client, path := getClientAndPath("Service", testClientMappings)
54
+	if client != kubeClient.RESTClient {
55
+		t.Errorf("Failed to get client for Service")
56
+	}
57
+	if path != "services" {
58
+		t.Errorf("Failed to get path for Service")
59
+	}
60
+}
61
+
47 62
 func ExampleApply() {
48 63
 	kubeClient, _ := kubeclient.New("127.0.0.1", nil)
49
-	clients := clientapi.ClientMappings{
50
-		"pods": {
51
-			Kind:   "Pod",
52
-			Client: kubeClient.RESTClient,
53
-		},
54
-		"services": {
55
-			Kind:   "Service",
56
-			Client: kubeClient.RESTClient,
57
-		},
64
+	testClientMappings := clientapi.ClientMappings{
65
+		"pods":     {"Pod", kubeClient.RESTClient},
66
+		"services": {"Service", kubeClient.RESTClient},
58 67
 	}
59 68
 	data, _ := ioutil.ReadFile("../../examples/guestbook/config.json")
60
-	errs := Apply(data, clients)
69
+	errs := Apply(data, testClientMappings)
61 70
 	fmt.Println(errs)
62 71
 	// Output:
63
-	// [The resource Service is not a known type - unable to create frontend The resource Service is not a known type - unable to create redismaster The resource Service is not a known type - unable to create redisslave The resource Pod is not a known type - unable to create redis-master-2 The resource ReplicationController is not a known type - unable to create frontendController The resource ReplicationController is not a known type - unable to create redisSlaveController]
64
-	//
72
+	// [[Service#frontend] Failed to create: Post http://127.0.0.1/api/v1beta1/services: dial tcp 127.0.0.1:80: connection refused [Service#redismaster] Failed to create: Post http://127.0.0.1/api/v1beta1/services: dial tcp 127.0.0.1:80: connection refused [Service#redisslave] Failed to create: Post http://127.0.0.1/api/v1beta1/services: dial tcp 127.0.0.1:80: connection refused [Pod#redis-master-2] Failed to create: Post http://127.0.0.1/api/v1beta1/pods: dial tcp 127.0.0.1:80: connection refused The resource ReplicationController is not a known type - unable to create frontendController The resource ReplicationController is not a known type - unable to create redisSlaveController]
65 73
 }