Skip to content
Merged
Show file tree
Hide file tree
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
75 changes: 71 additions & 4 deletions test/e2e/basic_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ func TestBasicWorkflow(t *testing.T) {
test.serviceCreate(t, "hello")
})

t.Run("create hello service again and get service already exists error", func(t *testing.T) {
test.serviceCreateDuplicate(t, "hello")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice nice, I wonder if we should also try to delete a service that’s already deleted? I would expect an error in case where service is already deleted (non-existent) and if the service is being deleted. Of course in the end the API should do the right thing and the client should return a “sensible” error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Good point. I can add a test for deleting a non-existent service to this PR.

})

t.Run("returns valid info about hello service", func(t *testing.T) {
test.serviceList(t, "hello")
test.serviceDescribe(t, "hello")
test.serviceDescribeWithPrintFlags(t, "hello")
})

t.Run("update hello service's configuration and returns no error", func(t *testing.T) {
Expand All @@ -59,13 +64,23 @@ func TestBasicWorkflow(t *testing.T) {
t.Run("returns a list of routes associated with hello and svc2 services", func(t *testing.T) {
test.routeList(t)
test.routeListWithArgument(t, "hello")
test.routeListWithPrintFlags(t, "hello", "svc2")
})

t.Run("describe route from hello service", func(t *testing.T) {
test.routeDescribe(t, "hello")
test.routeDescribeWithPrintFlags(t, "hello")
})

t.Run("delete hello and svc2 services and returns no error", func(t *testing.T) {
test.serviceDelete(t, "hello")
test.serviceDelete(t, "svc2")
})

t.Run("delete hello service again and get an error", func(t *testing.T) {
test.serviceDeleteNonexistent(t, "hello")
})

t.Run("returns no service after completing tests", func(t *testing.T) {
test.serviceListEmpty(t)
})
Expand All @@ -81,8 +96,7 @@ func (test *e2eTest) serviceListEmpty(t *testing.T) {
}

func (test *e2eTest) serviceCreate(t *testing.T, serviceName string) {
out, err := test.kn.RunWithOpts([]string{"service", "create",
fmt.Sprintf("%s", serviceName),
out, err := test.kn.RunWithOpts([]string{"service", "create", serviceName,
"--image", KnDefaultTestImage}, runOpts{NoNamespace: false})
assert.NilError(t, err)

Expand All @@ -93,8 +107,17 @@ func (test *e2eTest) serviceList(t *testing.T, serviceName string) {
out, err := test.kn.RunWithOpts([]string{"service", "list", serviceName}, runOpts{NoNamespace: false})
assert.NilError(t, err)

expectedOutput := fmt.Sprintf("%s", serviceName)
assert.Check(t, util.ContainsAll(out, expectedOutput))
assert.Check(t, util.ContainsAll(out, serviceName))
}

func (test *e2eTest) serviceCreateDuplicate(t *testing.T, serviceName string) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, this particular test case doesn't belong to basic_workflow_test as the filename suggest, but kind of testing for error handling mechanism, we should probably create another workflow which specifically aims at error handling test cases.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you all decide to move this to a more thorough IT (I am ambivalent at this point), please do the same for suggestion above on delete service.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be addressed as part of resolution to #301

out, err := test.kn.RunWithOpts([]string{"service", "list", serviceName}, runOpts{NoNamespace: false})
assert.Check(t, strings.Contains(out, serviceName), "The service does not exist yet")

_, err = test.kn.RunWithOpts([]string{"service", "create", serviceName,
"--image", KnDefaultTestImage}, runOpts{NoNamespace: false, AllowError: true})

assert.ErrorContains(t, err, "the service already exists")
}

func (test *e2eTest) revisionListForService(t *testing.T, serviceName string) {
Expand Down Expand Up @@ -132,6 +155,14 @@ func (test *e2eTest) serviceUpdate(t *testing.T, serviceName string, args []stri
assert.Check(t, util.ContainsAll(out, expectedOutput))
}

func (test *e2eTest) serviceDescribeWithPrintFlags(t *testing.T, serviceName string) {
out, err := test.kn.RunWithOpts([]string{"service", "describe", serviceName, "-o=name"}, runOpts{})
assert.NilError(t, err)

expectedName := fmt.Sprintf("service.serving.knative.dev/%s", serviceName)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this error message needs to be fixed on kn side, I will have a PR for this fix.

assert.Equal(t, strings.TrimSpace(out), expectedName)
}

func (test *e2eTest) routeList(t *testing.T) {
out, err := test.kn.RunWithOpts([]string{"route", "list"}, runOpts{})
assert.NilError(t, err)
Expand All @@ -154,3 +185,39 @@ func (test *e2eTest) serviceDelete(t *testing.T, serviceName string) {

assert.Check(t, util.ContainsAll(out, "Service", serviceName, "successfully deleted in namespace", test.kn.namespace))
}

func (test *e2eTest) serviceDeleteNonexistent(t *testing.T, serviceName string) {
out, err := test.kn.RunWithOpts([]string{"service", "list", serviceName}, runOpts{NoNamespace: false})
assert.Check(t, !strings.Contains(out, serviceName), "The service exists")

_, err = test.kn.RunWithOpts([]string{"service", "delete", serviceName}, runOpts{NoNamespace: false, AllowError: true})

expectedErr := fmt.Sprintf(`services.serving.knative.dev "%s" not found`, serviceName)
assert.ErrorContains(t, err, expectedErr)
}

func (test *e2eTest) routeDescribe(t *testing.T, routeName string) {
out, err := test.kn.RunWithOpts([]string{"route", "describe", routeName}, runOpts{})
assert.NilError(t, err)

expectedGVK := `apiVersion: serving.knative.dev/v1alpha1
kind: Route`
expectedNamespace := fmt.Sprintf("namespace: %s", test.kn.namespace)
expectedServiceLabel := fmt.Sprintf("serving.knative.dev/service: %s", routeName)
assert.Check(t, util.ContainsAll(out, expectedGVK, expectedNamespace, expectedServiceLabel))
}

func (test *e2eTest) routeDescribeWithPrintFlags(t *testing.T, routeName string) {
out, err := test.kn.RunWithOpts([]string{"route", "describe", routeName, "-o=name"}, runOpts{})
assert.NilError(t, err)

expectedName := fmt.Sprintf("route.serving.knative.dev/%s", routeName)
assert.Equal(t, strings.TrimSpace(out), expectedName)
}

func (test *e2eTest) routeListWithPrintFlags(t *testing.T, names ...string) {
out, err := test.kn.RunWithOpts([]string{"route", "list", "-o=jsonpath={.items[*].metadata.name}"}, runOpts{})
assert.NilError(t, err)

assert.Check(t, util.ContainsAll(out, names...))
}
48 changes: 40 additions & 8 deletions test/e2e/revision_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package e2e

import (
"fmt"
"strings"
"testing"

Expand All @@ -33,26 +34,57 @@ func TestRevisionWorkflow(t *testing.T) {
test.serviceCreate(t, "hello")
})

t.Run("describe revision from hello service", func(t *testing.T) {
test.revisionDescribe(t, "hello")
test.revisionDescribeWithPrintFlags(t, "hello")
})

t.Run("delete latest revision from hello service and returns no error", func(t *testing.T) {
test.deleteRevision(t, "hello")
test.revisionDelete(t, "hello")
})

t.Run("delete hello service and returns no error", func(t *testing.T) {
test.serviceDelete(t, "hello")
})
}

// Private
func (test *e2eTest) revisionDelete(t *testing.T, serviceName string) {
revName := test.findRevision(t, serviceName)

out, err := test.kn.RunWithOpts([]string{"revision", "delete", revName}, runOpts{})
assert.NilError(t, err)

assert.Check(t, util.ContainsAll(out, "Revision", revName, "deleted", "namespace", test.kn.namespace))
}

func (test *e2eTest) revisionDescribe(t *testing.T, serviceName string) {
revName := test.findRevision(t, serviceName)

func (test *e2eTest) deleteRevision(t *testing.T, serviceName string) {
out, err := test.kn.RunWithOpts([]string{"revision", "describe", revName}, runOpts{})
assert.NilError(t, err)

expectedGVK := `apiVersion: serving.knative.dev/v1alpha1
kind: Revision`
expectedNamespace := fmt.Sprintf("namespace: %s", test.kn.namespace)
expectedServiceLabel := fmt.Sprintf("serving.knative.dev/service: %s", serviceName)
assert.Check(t, util.ContainsAll(out, expectedGVK, expectedNamespace, expectedServiceLabel))
}

func (test *e2eTest) revisionDescribeWithPrintFlags(t *testing.T, serviceName string) {
revName := test.findRevision(t, serviceName)

out, err := test.kn.RunWithOpts([]string{"revision", "describe", revName, "-o=name"}, runOpts{})
assert.NilError(t, err)

expectedName := fmt.Sprintf("revision.serving.knative.dev/%s", revName)
assert.Equal(t, strings.TrimSpace(out), expectedName)
}

func (test *e2eTest) findRevision(t *testing.T, serviceName string) string {
revName, err := test.kn.RunWithOpts([]string{"revision", "list", "-o=jsonpath={.items[0].metadata.name}"}, runOpts{})
assert.NilError(t, err)
if strings.Contains(revName, "No resources found.") {
t.Errorf("Could not find revision name.")
}

out, err := test.kn.RunWithOpts([]string{"revision", "delete", revName}, runOpts{})
assert.NilError(t, err)

assert.Check(t, util.ContainsAll(out, "Revision", revName, "deleted", "namespace", test.kn.namespace))
return revName
}