test(service): Add e2e tests for min, max scale options (#300)

* test(service): Add e2e tests for min, max scale options

 add e2e tests for min, max scale options for `service create` and
 `service update` operations.

* Provision in tests for jsonpath to lookup old and new fields
This commit is contained in:
Navid Shaikh 2019-07-27 01:32:49 +05:30 committed by Knative Prow Robot
parent 152305f334
commit df816e63fe
2 changed files with 48 additions and 1 deletions

View File

@ -26,4 +26,4 @@ echo "📋 Formatting"
go fmt ${base}/test/e2e/...
echo "🧪 Testing"
go test ${base}/test/e2e/ -test.v --tags 'e2e'
go test ${base}/test/e2e/ -test.v --tags 'e2e'

View File

@ -53,6 +53,21 @@ func TestServiceOptions(t *testing.T) {
t.Run("delete service", func(t *testing.T) {
test.serviceDelete(t, "svc1")
})
t.Run("create and validate service with min/max scale options ", func(t *testing.T) {
test.serviceCreateWithOptions(t, "svc2", []string{"--min-scale", "1", "--max-scale", "3"})
test.validateServiceMinScale(t, "svc2", "1")
test.validateServiceMaxScale(t, "svc2", "3")
})
t.Run("update and validate service with max scale option", func(t *testing.T) {
test.serviceUpdate(t, "svc2", []string{"--max-scale", "2"})
test.validateServiceMaxScale(t, "svc2", "2")
})
t.Run("delete service", func(t *testing.T) {
test.serviceDelete(t, "svc2")
})
}
func (test *e2eTest) serviceCreateWithOptions(t *testing.T, serviceName string, options []string) {
@ -94,3 +109,35 @@ func (test *e2eTest) validateServiceConcurrencyTarget(t *testing.T, serviceName,
assert.Equal(t, out, concurrencyTarget)
}
}
func (test *e2eTest) validateServiceMinScale(t *testing.T, serviceName, minScale string) {
jsonpath := "jsonpath={.items[0].spec.template.metadata.annotations.autoscaling\\.knative\\.dev/minScale}"
out, err := test.kn.RunWithOpts([]string{"service", "list", serviceName, "-o", jsonpath}, runOpts{})
assert.NilError(t, err)
if out != "" {
assert.Equal(t, minScale, out)
} else {
// case where server could return either old or new fields
// #TODO: remove this when old fields are deprecated, v1beta1
jsonpath = "jsonpath={.items[0].spec.runLatest.configuration.revisionTemplate.metadata.annotations.autoscaling\\.knative\\.dev/minScale}"
out, err := test.kn.RunWithOpts([]string{"service", "list", serviceName, "-o", jsonpath}, runOpts{})
assert.NilError(t, err)
assert.Equal(t, minScale, out)
}
}
func (test *e2eTest) validateServiceMaxScale(t *testing.T, serviceName, maxScale string) {
jsonpath := "jsonpath={.items[0].spec.template.metadata.annotations.autoscaling\\.knative\\.dev/maxScale}"
out, err := test.kn.RunWithOpts([]string{"service", "list", serviceName, "-o", jsonpath}, runOpts{})
assert.NilError(t, err)
if out != "" {
assert.Equal(t, maxScale, out)
} else {
// case where server could return either old or new fields
// #TODO: remove this when old fields are deprecated, v1beta1
jsonpath = "jsonpath={.items[0].spec.runLatest.configuration.revisionTemplate.metadata.annotations.autoscaling\\.knative\\.dev/maxScale}"
out, err := test.kn.RunWithOpts([]string{"service", "list", serviceName, "-o", jsonpath}, runOpts{})
assert.NilError(t, err)
assert.Equal(t, maxScale, out)
}
}