Skip to content

Commit

Permalink
some test cleanup, comments to explain CI tags
Browse files Browse the repository at this point in the history
  • Loading branch information
robscott committed Dec 26, 2018
1 parent 554faad commit 5715c25
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ workflows:
- test
- build:
context: org-global
# Allow using testing tags for testing circle test + build steps
filters:
tags:
only: /^testing-.*/
Expand All @@ -55,5 +56,6 @@ workflows:
filters:
branches:
ignore: /.*/
# Testing tags are reserved for testing circle test + build steps
tags:
ignore: /^testing-.*/
40 changes: 15 additions & 25 deletions pkg/validator/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ func TestValidateResourcesEmptyContainer(t *testing.T) {
Name: "Empty",
}

cv := ContainerValidation{
Container: container,
}

expected := conf.RequestsAndLimits{
resourceConf := conf.RequestsAndLimits{
Requests: conf.ResourceList{
"cpu": conf.ResourceMinMax{
Min: "100m",
Expand All @@ -71,8 +67,6 @@ func TestValidateResourcesEmptyContainer(t *testing.T) {
},
}

cv.validateResources(expected)

expectedFailures := []types.Failure{
{
Name: "requests.cpu",
Expand All @@ -96,8 +90,7 @@ func TestValidateResourcesEmptyContainer(t *testing.T) {
},
}

assert.Len(t, cv.Failures, len(expectedFailures))
assert.ElementsMatch(t, cv.Failures, expectedFailures)
testValidateResources(t, &container, &resourceConf, &expectedFailures)
}

func TestValidateResourcesPartiallyValid(t *testing.T) {
Expand All @@ -119,11 +112,7 @@ func TestValidateResourcesPartiallyValid(t *testing.T) {
},
}

cv := ContainerValidation{
Container: container,
}

expected := conf.RequestsAndLimits{
resourceConf := conf.RequestsAndLimits{
Requests: conf.ResourceList{
"cpu": conf.ResourceMinMax{
Min: "100m",
Expand All @@ -146,8 +135,6 @@ func TestValidateResourcesPartiallyValid(t *testing.T) {
},
}

cv.validateResources(expected)

expectedFailures := []types.Failure{
{
Name: "requests.memory",
Expand All @@ -161,8 +148,7 @@ func TestValidateResourcesPartiallyValid(t *testing.T) {
},
}

assert.Len(t, cv.Failures, len(expectedFailures))
assert.ElementsMatch(t, cv.Failures, expectedFailures)
testValidateResources(t, &container, &resourceConf, &expectedFailures)
}

func TestValidateResourcesFullyValid(t *testing.T) {
Expand Down Expand Up @@ -192,11 +178,7 @@ func TestValidateResourcesFullyValid(t *testing.T) {
},
}

cv := ContainerValidation{
Container: container,
}

expected := conf.RequestsAndLimits{
resourceConf := conf.RequestsAndLimits{
Requests: conf.ResourceList{
"cpu": conf.ResourceMinMax{
Min: "100m",
Expand All @@ -219,7 +201,15 @@ func TestValidateResourcesFullyValid(t *testing.T) {
},
}

cv.validateResources(expected)
testValidateResources(t, &container, &resourceConf, &[]types.Failure{})
}

assert.Len(t, cv.Failures, 0)
func testValidateResources(t *testing.T, container *corev1.Container, conf *conf.RequestsAndLimits, expectedFailures *[]types.Failure) {
cv := ContainerValidation{
Container: *container,
}

cv.validateResources(*conf)
assert.Len(t, cv.Failures, len(*expectedFailures))
assert.ElementsMatch(t, cv.Failures, *expectedFailures)
}

0 comments on commit 5715c25

Please sign in to comment.