| 63 | } |
| 64 | |
| 65 | func TestServiceAnalyzerNamespaceFiltering(t *testing.T) { |
| 66 | |
| 67 | clientset := fake.NewSimpleClientset( |
| 68 | &v1.Endpoints{ |
| 69 | ObjectMeta: metav1.ObjectMeta{ |
| 70 | Name: "example", |
| 71 | Namespace: "default", |
| 72 | Annotations: map[string]string{}, |
| 73 | }, |
| 74 | }, |
| 75 | &v1.Service{ |
| 76 | ObjectMeta: metav1.ObjectMeta{ |
| 77 | Name: "example", |
| 78 | Namespace: "default", |
| 79 | Annotations: map[string]string{}, |
| 80 | }, |
| 81 | Spec: v1.ServiceSpec{ |
| 82 | Selector: map[string]string{ |
| 83 | "app": "example", |
| 84 | }, |
| 85 | }, |
| 86 | }, |
| 87 | &v1.Endpoints{ |
| 88 | ObjectMeta: metav1.ObjectMeta{ |
| 89 | Name: "example", |
| 90 | Namespace: "other-namespace", |
| 91 | Annotations: map[string]string{}, |
| 92 | }, |
| 93 | }, |
| 94 | &v1.Service{ |
| 95 | ObjectMeta: metav1.ObjectMeta{ |
| 96 | Name: "example", |
| 97 | Namespace: "other-namespace", |
| 98 | Annotations: map[string]string{}, |
| 99 | }, |
| 100 | Spec: v1.ServiceSpec{ |
| 101 | Selector: map[string]string{ |
| 102 | "app": "example", |
| 103 | }, |
| 104 | }, |
| 105 | }, |
| 106 | ) |
| 107 | |
| 108 | config := Analyzer{ |
| 109 | Client: &Client{ |
| 110 | Client: clientset, |
| 111 | }, |
| 112 | Context: context.Background(), |
| 113 | Namespace: "default", |
| 114 | } |
| 115 | |
| 116 | serviceAnalyzer := ServiceAnalyzer{} |
| 117 | analysisResults, err := serviceAnalyzer.Analyze(config) |
| 118 | if err != nil { |
| 119 | t.Error(err) |
| 120 | } |
| 121 | assert.Equal(t, len(analysisResults), 1) |
| 122 | } |