Skip to content
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

Add e2e test for different service and revision label #766

Merged
merged 2 commits into from
Apr 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions test/e2e/service_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func TestServiceOptions(t *testing.T) {
validateUserID(r, "svc6", uid)
serviceUpdate(r, "svc6", "--user", strconv.FormatInt(uid+1, 10))
validateUserID(r, "svc6", uid+1)

t.Log("create and validate service and revision labels")
serviceCreateWithOptions(r, "svc7", "--label-service", "svc=helloworld-svc", "--label-revision", "rev=helloworld-rev")
validateLabels(r, "svc7", map[string]string{"svc": "helloworld-svc"}, map[string]string{"rev": "helloworld-rev"})
}

func serviceCreateWithOptions(r *test.KnRunResultCollector, serviceName string, options ...string) {
Expand Down Expand Up @@ -171,6 +175,20 @@ func validateServiceAnnotations(r *test.KnRunResultCollector, serviceName string
}
}

func validateLabels(r *test.KnRunResultCollector, serviceName string, expectedServiceLabels, expectedRevisionLabels map[string]string) {
out := r.KnTest().Kn().Run("service", "describe", serviceName, "-ojson")
data := json.NewDecoder(strings.NewReader(out.Stdout))
var service servingv1.Service
err := data.Decode(&service)
assert.NilError(r.T(), err)

gotRevisionLabels := service.Spec.Template.ObjectMeta.GetLabels()
assert.DeepEqual(r.T(), gotRevisionLabels, expectedRevisionLabels)

gotServiceLabels := service.ObjectMeta.GetLabels()
assert.DeepEqual(r.T(), gotServiceLabels, expectedServiceLabels)
}

func validateContainerField(r *test.KnRunResultCollector, serviceName, field, expected string) {
jsonpath := fmt.Sprintf("jsonpath={.items[0].spec.template.spec.containers[0].%s}", field)
out := r.KnTest().Kn().Run("service", "list", serviceName, "-o", jsonpath)
Expand Down