-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix test fixtures, add a test for controllers #455
Changes from 8 commits
6ebf8b0
d7e24ca
a06f99b
7fe240f
bf80437
5ab0e59
03610d3
ce60411
ad56cc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,12 +27,12 @@ func TestGetResourcesFromPath(t *testing.T) { | |
assert.Equal(t, 1, len(resources.Namespaces), "Should have a namespace") | ||
assert.Equal(t, "two", resources.Namespaces[0].ObjectMeta.Name) | ||
|
||
assert.Equal(t, 8, len(resources.Controllers), "Should have eight controllers") | ||
assert.Equal(t, 9, len(resources.Controllers), "Should have eight controllers") | ||
namespaceCount := map[string]int{} | ||
for _, controller := range resources.Controllers { | ||
namespaceCount[controller.ObjectMeta.GetNamespace()]++ | ||
} | ||
assert.Equal(t, 7, namespaceCount[""], "Should have seven controller in default namespace") | ||
assert.Equal(t, 8, namespaceCount[""], "Should have seven controller in default namespace") | ||
assert.Equal(t, 1, namespaceCount["two"], "Should have one controller in namespace 'two'") | ||
} | ||
|
||
|
@@ -87,10 +87,7 @@ func TestAddResourcesFromReader(t *testing.T) { | |
} | ||
|
||
func TestGetResourceFromAPI(t *testing.T) { | ||
k8s, dynamicInterface := test.SetupTestAPI() | ||
k8s = test.SetupAddControllers(context.Background(), k8s, "test") | ||
// TODO find a way to mock out the dynamic client | ||
// and create fake pods in order to find all of the controllers. | ||
k8s, dynamicInterface := test.SetupTestAPI(test.GetMockControllers("test")...) | ||
resources, err := CreateResourceProviderFromAPI(context.Background(), k8s, "test", &dynamicInterface) | ||
assert.Equal(t, nil, err, "Error should be nil") | ||
|
||
|
@@ -99,7 +96,19 @@ func TestGetResourceFromAPI(t *testing.T) { | |
assert.IsType(t, time.Now(), resources.CreationTime, "Creation time should be set") | ||
|
||
assert.Equal(t, 0, len(resources.Nodes), "Should not have any nodes") | ||
assert.Equal(t, 1, len(resources.Controllers), "Should have 1 controller") | ||
|
||
assert.Equal(t, "", resources.Controllers[0].ObjectMeta.GetName()) | ||
assert.Equal(t, 5, len(resources.Controllers), "Should have 5 controllers") | ||
|
||
expectedNames := map[string]bool{ | ||
"deploy": false, | ||
"job": false, | ||
"cronjob": false, | ||
"statefulset": false, | ||
"daemonset": false, | ||
} | ||
for _, ctrl := range resources.Controllers { | ||
expectedNames[ctrl.ObjectMeta.GetName()] = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this way of handling. I wonder if the assert library we use has something built in already or if we could contribute to it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's something like it, but it expects the same object type |
||
} | ||
for name, val := range expectedNames { | ||
assert.Equal(t, true, val, name) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: Deployment | ||
metadata: | ||
name: test-deployment-2 | ||
spec: | ||
replicas: 2 | ||
selector: | ||
matchLabels: | ||
app: test-deployment | ||
template: | ||
metadata: | ||
labels: | ||
app: test-deployment | ||
spec: | ||
containers: | ||
- name: ubuntu | ||
image: ubuntu | ||
ports: | ||
- containerPort: 3000 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should get rid of these messages, both of them are out of sync now.