Skip to content

Commit

Permalink
add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Daisy Guo committed Apr 3, 2020
1 parent 4eb5f64 commit 1a37704
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/util/unstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"k8s.io/apimachinery/pkg/runtime"
)

// ToUnstructuredList is to converts an object to unstructured.UnstructuredList.
// If the object is not a list type, it will convert to a single item UnstructuredList.
func ToUnstructuredList(obj runtime.Object) (*unstructured.UnstructuredList, error) {
unstructuredList := &unstructured.UnstructuredList{}
unstructuredList.SetGroupVersionKind(obj.GetObjectKind().GroupVersionKind())
Expand All @@ -30,16 +32,20 @@ func ToUnstructuredList(obj runtime.Object) (*unstructured.UnstructuredList, err
if err != nil {
return nil, err
}
for _, obj := range items {
ud, err := toUnstructured(obj)
for _, obji := range items {
ud, err := toUnstructured(obji)
if err != nil {
return nil, err
}
unstructuredList.Items = append(unstructuredList.Items, *ud)
}

} else {

ud, err := toUnstructured(obj)
if err != nil {
return nil, err
}
unstructuredList.Items = append(unstructuredList.Items, *ud)
}
return unstructuredList, nil

Expand Down
9 changes: 9 additions & 0 deletions test/e2e/basic_workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func TestBasicWorkflow(t *testing.T) {
test.serviceList(t, r, "hello")
test.serviceDescribe(t, r, "hello")

t.Log("return list --output name about hello service")
test.serviceListOutput(t, r, "hello")

t.Log("update hello service's configuration and return no error")
test.serviceUpdate(t, r, "hello", "--env", "TARGET=kn", "--port", "8888")

Expand Down Expand Up @@ -102,6 +105,12 @@ func (test *e2eTest) serviceList(t *testing.T, r *KnRunResultCollector, serviceN
assert.Check(t, util.ContainsAll(out.Stdout, serviceName))
}

func (test *e2eTest) serviceListOutput(t *testing.T, r *KnRunResultCollector, serviceName string) {
out := test.kn.Run("service", "list", serviceName, "--output", "name")
r.AssertNoError(out)
assert.Check(t, util.ContainsAll(out.Stdout, serviceName, "service.serving.knative.dev"))
}

func (test *e2eTest) serviceDescribe(t *testing.T, r *KnRunResultCollector, serviceName string) {
out := test.kn.Run("service", "describe", serviceName)
r.AssertNoError(out)
Expand Down

0 comments on commit 1a37704

Please sign in to comment.