| 
									
										
										
										
											2019-03-22 08:32:40 -06:00
										 |  |  | package kubernetes | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"testing" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestFilteredNamespaceExists(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2019-04-08 11:13:46 +01:00
										 |  |  | 	tests := []struct { | 
					
						
							| 
									
										
										
										
											2019-03-22 08:32:40 -06:00
										 |  |  | 		expected             bool | 
					
						
							|  |  |  | 		kubernetesNamespaces map[string]struct{} | 
					
						
							|  |  |  | 		testNamespace        string | 
					
						
							|  |  |  | 	}{ | 
					
						
							| 
									
										
										
										
											2019-04-08 11:13:46 +01:00
										 |  |  | 		{true, map[string]struct{}{}, "foobar"}, | 
					
						
							|  |  |  | 		{false, map[string]struct{}{}, "nsnoexist"}, | 
					
						
							| 
									
										
										
										
											2019-03-22 08:32:40 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	k := Kubernetes{} | 
					
						
							|  |  |  | 	k.APIConn = &APIConnServeTest{} | 
					
						
							|  |  |  | 	for i, test := range tests { | 
					
						
							|  |  |  | 		k.Namespaces = test.kubernetesNamespaces | 
					
						
							|  |  |  | 		actual := k.filteredNamespaceExists(test.testNamespace) | 
					
						
							|  |  |  | 		if actual != test.expected { | 
					
						
							|  |  |  | 			t.Errorf("Test %d failed. Filtered namespace %s was expected to exist", i, test.testNamespace) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestNamespaceExposed(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2019-04-08 11:13:46 +01:00
										 |  |  | 	tests := []struct { | 
					
						
							| 
									
										
										
										
											2019-03-22 08:32:40 -06:00
										 |  |  | 		expected             bool | 
					
						
							|  |  |  | 		kubernetesNamespaces map[string]struct{} | 
					
						
							|  |  |  | 		testNamespace        string | 
					
						
							|  |  |  | 	}{ | 
					
						
							| 
									
										
										
										
											2019-04-08 11:13:46 +01:00
										 |  |  | 		{true, map[string]struct{}{"foobar": {}}, "foobar"}, | 
					
						
							|  |  |  | 		{false, map[string]struct{}{"foobar": {}}, "nsnoexist"}, | 
					
						
							|  |  |  | 		{true, map[string]struct{}{}, "foobar"}, | 
					
						
							|  |  |  | 		{true, map[string]struct{}{}, "nsnoexist"}, | 
					
						
							| 
									
										
										
										
											2019-03-22 08:32:40 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	k := Kubernetes{} | 
					
						
							|  |  |  | 	k.APIConn = &APIConnServeTest{} | 
					
						
							|  |  |  | 	for i, test := range tests { | 
					
						
							|  |  |  | 		k.Namespaces = test.kubernetesNamespaces | 
					
						
							|  |  |  | 		actual := k.configuredNamespace(test.testNamespace) | 
					
						
							|  |  |  | 		if actual != test.expected { | 
					
						
							|  |  |  | 			t.Errorf("Test %d failed. Namespace %s was expected to be exposed", i, test.testNamespace) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestNamespaceValid(t *testing.T) { | 
					
						
							| 
									
										
										
										
											2019-04-08 11:13:46 +01:00
										 |  |  | 	tests := []struct { | 
					
						
							| 
									
										
										
										
											2019-03-22 08:32:40 -06:00
										 |  |  | 		expected             bool | 
					
						
							|  |  |  | 		kubernetesNamespaces map[string]struct{} | 
					
						
							|  |  |  | 		testNamespace        string | 
					
						
							|  |  |  | 	}{ | 
					
						
							| 
									
										
										
										
											2019-04-08 11:13:46 +01:00
										 |  |  | 		{true, map[string]struct{}{"foobar": {}}, "foobar"}, | 
					
						
							|  |  |  | 		{false, map[string]struct{}{"foobar": {}}, "nsnoexist"}, | 
					
						
							|  |  |  | 		{true, map[string]struct{}{}, "foobar"}, | 
					
						
							|  |  |  | 		{false, map[string]struct{}{}, "nsnoexist"}, | 
					
						
							| 
									
										
										
										
											2019-03-22 08:32:40 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	k := Kubernetes{} | 
					
						
							|  |  |  | 	k.APIConn = &APIConnServeTest{} | 
					
						
							|  |  |  | 	for i, test := range tests { | 
					
						
							|  |  |  | 		k.Namespaces = test.kubernetesNamespaces | 
					
						
							|  |  |  | 		actual := k.namespaceExposed(test.testNamespace) | 
					
						
							|  |  |  | 		if actual != test.expected { | 
					
						
							|  |  |  | 			t.Errorf("Test %d failed. Namespace %s was expected to be valid", i, test.testNamespace) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |