Created
July 11, 2019 15:07
-
-
Save jonathanbeber/33adb4bb051142eb2a30e24e938933ba to your computer and use it in GitHub Desktop.
api_test.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/controller/k8s/api_test.go b/controller/k8s/api_test.go | |
index 49ce74f2..a917a204 100644 | |
--- a/controller/k8s/api_test.go | |
+++ b/controller/k8s/api_test.go | |
@@ -878,11 +878,12 @@ status: | |
if err != exp.err { | |
t.Fatalf("api.GetPodsFor() unexpected error, expected [%s] got: [%s]", exp.err, err) | |
} | |
- | |
- sort.Sort(podByUID(pods)) | |
- sort.Sort(podByUID(k8sResultPods)) | |
- if !reflect.DeepEqual(pods, k8sResultPods) { | |
- t.Fatalf("Expected: %+v, Got: %+v", k8sResultPods, pods) | |
+ a := podByName(pods) | |
+ b := podByName(k8sResultPods) | |
+ sort.Sort(a) | |
+ sort.Sort(b) | |
+ if !reflect.DeepEqual(a, b) { | |
+ t.Fatalf("Expected: %+v, Got: %+v", a, b) | |
} | |
} | |
}) | |
@@ -1234,12 +1235,13 @@ spec: | |
if err != exp.err { | |
t.Fatalf("api.GetServicesFor() unexpected error, expected [%s] got: [%s]", exp.err, err) | |
} | |
+ a := serviceByName(k8sResultServices) | |
+ b := serviceByName(services) | |
+ sort.Sort(a) | |
+ sort.Sort(b) | |
- sort.Sort(serviceByUID(k8sResultServices)) | |
- sort.Sort(serviceByUID(services)) | |
- | |
- if !reflect.DeepEqual(services, k8sResultServices) { | |
- t.Fatalf("Expected: %+v, Got: %+v", k8sResultServices, services) | |
+ if !reflect.DeepEqual(a, b) { | |
+ t.Fatalf("Expected: %+v, Got: %+v", a, b) | |
} | |
} | |
diff --git a/controller/k8s/test_helper.go b/controller/k8s/test_helper.go | |
index 0a64d7cd..91a6cdb9 100644 | |
--- a/controller/k8s/test_helper.go | |
+++ b/controller/k8s/test_helper.go | |
@@ -3,7 +3,6 @@ package k8s | |
import ( | |
"github.com/linkerd/linkerd2/pkg/k8s" | |
corev1 "k8s.io/api/core/v1" | |
- "k8s.io/apimachinery/pkg/types" | |
) | |
// NewFakeAPI provides a mock Kubernetes API for testing. | |
@@ -35,29 +34,29 @@ func NewFakeAPI(configs ...string) (*API, error) { | |
} | |
type hasUID interface { | |
- GetUID() types.UID | |
+ GetName() string | |
} | |
-type byUID []hasUID | |
+type byName []hasUID | |
-func (s byUID) Len() int { return len(s) } | |
+func (s byName) Len() int { return len(s) } | |
-func (s byUID) Swap(i, j int) { s[i], s[j] = s[j], s[i] } | |
+func (s byName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } | |
-func (s byUID) Less(i, j int) bool { return s[i].GetUID() < s[j].GetUID() } | |
+func (s byName) Less(i, j int) bool { return s[i].GetName() < s[j].GetName() } | |
-func podByUID(pods []*corev1.Pod) byUID { | |
- uids := make(byUID, len(pods)) | |
+func podByName(pods []*corev1.Pod) byName { | |
+ names := make(byName, len(pods)) | |
for i := range pods { | |
- uids[i] = pods[i] | |
+ names[i] = pods[i] | |
} | |
- return uids | |
+ return names | |
} | |
-func serviceByUID(services []*corev1.Service) byUID { | |
- uids := make(byUID, len(services)) | |
+func serviceByName(services []*corev1.Service) byName { | |
+ names := make(byName, len(services)) | |
for i := range services { | |
- uids[i] = services[i] | |
+ names[i] = services[i] | |
} | |
- return uids | |
+ return names | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment