diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index ed6061efc7..493be7aee0 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -20,8 +20,8 @@ |=== | 🐣 -| Refactor `e2e` common code into `lib\test\integration` -| https://github.com/knative/client/pull/764[#764] +| Refactor `e2e` common code into `lib/test/integration` +| https://github.com/knative/client/pull/765[#765] ## v0.13.1 (2020-03-25) diff --git a/lib/test/integration/cli.go b/lib/test/integration/cli.go index d253555f64..cd74c5748a 100644 --- a/lib/test/integration/cli.go +++ b/lib/test/integration/cli.go @@ -28,6 +28,7 @@ const ( seperatorLight = "╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍╍" ) +// Kn type type Kn struct { namespace string } @@ -37,7 +38,7 @@ func NewKn() Kn { return Kn{} } -// Run the 'kn' CLI with args and opts +// Run the 'kn' CLI with args func (k Kn) Run(args ...string) KnRunResult { return RunKn(k.namespace, args) } @@ -47,24 +48,24 @@ func (k Kn) Namespace() string { return k.namespace } -// Helper methods for calling out to the test cluster +// Kubectl type type Kubectl struct { namespace string } -// New Kn object +// New Kubectl object func NewKubectl(namespace string) Kubectl { return Kubectl{ namespace: namespace, } } -// Run the 'kubectl' CLI with args and opts +// Run the 'kubectl' CLI with args func (k Kubectl) Run(args ...string) (string, error) { return RunKubectl(k.namespace, args...) } -// Namespace that this Kn instance uses +// Namespace that this Kubectl instance uses func (k Kubectl) Namespace() string { return k.namespace } diff --git a/lib/test/integration/integration.go b/lib/test/integration/integration.go index 1ab47c05b0..c686afa534 100644 --- a/lib/test/integration/integration.go +++ b/lib/test/integration/integration.go @@ -38,24 +38,14 @@ var serviceMutex sync.Mutex var serviceCount int var namespaceCount int -// IntegrationTest struct -type Test struct { +// KnTest type +type KnTest struct { namespace string kn Kn } -// Teardown clean up -func (test *Test) Teardown() error { - return DeleteNamespace(test.namespace) -} - -// Teardown clean up -func (test *Test) Kn() Kn { - return test.kn -} - // NewIntegrationTest creates a new ItegrationTest object -func NewIntegrationTest() (*Test, error) { +func NewKnTest() (*KnTest, error) { ns := NextNamespace() err := CreateNamespace(ns) @@ -67,12 +57,24 @@ func NewIntegrationTest() (*Test, error) { return nil, err } - return &Test{ + return &KnTest{ namespace: ns, kn: Kn{ns}, }, nil } +// Teardown clean up +func (test *KnTest) Teardown() error { + return DeleteNamespace(test.namespace) +} + +// Teardown clean up +func (test *KnTest) Kn() Kn { + return test.kn +} + +// Public functions + // NextNamespace return the next unique namespace func NextNamespace() string { ns := os.Getenv("KN_E2E_NAMESPACE") diff --git a/lib/test/integration/result_collector.go b/lib/test/integration/result_collector.go index af92a2c9ca..c9a57229cd 100644 --- a/lib/test/integration/result_collector.go +++ b/lib/test/integration/result_collector.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Knative Authors +// Copyright 2020 The Knative Authors // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ import ( "testing" ) -// Result of a "kn" call +// KnRunResult holds command and result artifacts of a "kn" call type KnRunResult struct { // Command line called CmdLine string diff --git a/test/e2e/basic_workflow_test.go b/test/e2e/basic_workflow_test.go index 0bcd7e80cb..d9549b422c 100644 --- a/test/e2e/basic_workflow_test.go +++ b/test/e2e/basic_workflow_test.go @@ -29,7 +29,7 @@ import ( func TestBasicWorkflow(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { assert.NilError(t, it.Teardown()) @@ -85,25 +85,25 @@ func TestWrongCommand(t *testing.T) { // ========================================================================== -func serviceListEmpty(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector) { +func serviceListEmpty(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector) { out := it.Kn().Run("service", "list") r.AssertNoError(out) assert.Check(t, util.ContainsAll(out.Stdout, "No services found.")) } -func serviceCreate(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string) { +func serviceCreate(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string) { out := it.Kn().Run("service", "create", serviceName, "--image", integration.KnDefaultTestImage) r.AssertNoError(out) assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "service", serviceName, "creating", "namespace", it.Kn().Namespace(), "ready")) } -func serviceList(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string) { +func serviceList(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string) { out := it.Kn().Run("service", "list", serviceName) r.AssertNoError(out) assert.Check(t, util.ContainsAll(out.Stdout, serviceName)) } -func serviceDescribe(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string) { +func serviceDescribe(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string) { out := it.Kn().Run("service", "describe", serviceName) r.AssertNoError(out) assert.Assert(t, util.ContainsAll(out.Stdout, serviceName, it.Kn().Namespace(), integration.KnDefaultTestImage)) @@ -111,7 +111,7 @@ func serviceDescribe(t *testing.T, it *integration.Test, r *integration.KnRunRes assert.Assert(t, util.ContainsAll(out.Stdout, "Name", "Namespace", "URL", "Age", "Revisions")) } -func serviceUpdate(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string, args ...string) { +func serviceUpdate(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string, args ...string) { fullArgs := append([]string{}, "service", "update", serviceName) fullArgs = append(fullArgs, args...) out := it.Kn().Run(fullArgs...) @@ -119,13 +119,13 @@ func serviceUpdate(t *testing.T, it *integration.Test, r *integration.KnRunResul assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "updating", "service", serviceName, "ready")) } -func serviceDelete(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string) { +func serviceDelete(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string) { out := it.Kn().Run("service", "delete", serviceName) r.AssertNoError(out) assert.Check(t, util.ContainsAll(out.Stdout, "Service", serviceName, "successfully deleted in namespace", it.Kn().Namespace())) } -func revisionListForService(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string) { +func revisionListForService(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string) { out := it.Kn().Run("revision", "list", "-s", serviceName) r.AssertNoError(out) outputLines := strings.Split(out.Stdout, "\n") @@ -137,7 +137,7 @@ func revisionListForService(t *testing.T, it *integration.Test, r *integration.K } } -func revisionDescribe(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string) { +func revisionDescribe(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string) { revName := findRevision(t, it, r, serviceName) out := it.Kn().Run("revision", "describe", revName) diff --git a/test/e2e/ping_test.go b/test/e2e/ping_test.go index a36b186738..617e0550f2 100644 --- a/test/e2e/ping_test.go +++ b/test/e2e/ping_test.go @@ -28,7 +28,7 @@ import ( func TestSourcePing(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { assert.NilError(t, it.Teardown()) @@ -65,34 +65,34 @@ func TestSourcePing(t *testing.T) { verifyPingSourceDescribe(t, it, r, "testpingsource3", "*/1 * * * *", mymsg, "testsvc1") } -func pingSourceCreate(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, sourceName string, schedule string, data string, sink string) { +func pingSourceCreate(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, sourceName string, schedule string, data string, sink string) { out := it.Kn().Run("source", "ping", "create", sourceName, "--schedule", schedule, "--data", data, "--sink", sink) assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "created", "namespace", it.Kn().Namespace())) r.AssertNoError(out) } -func pingSourceDelete(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, sourceName string) { +func pingSourceDelete(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, sourceName string) { out := it.Kn().Run("source", "ping", "delete", sourceName) assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "deleted", "namespace", it.Kn().Namespace())) r.AssertNoError(out) } -func pingSourceCreateMissingSink(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, sourceName string, schedule string, data string, sink string) { +func pingSourceCreateMissingSink(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, sourceName string, schedule string, data string, sink string) { out := it.Kn().Run("source", "ping", "create", sourceName, "--schedule", schedule, "--data", data, "--sink", sink) assert.Check(t, util.ContainsAll(out.Stderr, "services.serving.knative.dev", "not found")) r.AssertError(out) } -func pingSourceUpdateSink(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, sourceName string, sink string) { +func pingSourceUpdateSink(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, sourceName string, sink string) { out := it.Kn().Run("source", "ping", "update", sourceName, "--sink", sink) assert.Check(t, util.ContainsAll(out.Stdout, sourceName, "updated", "namespace", it.Kn().Namespace())) r.AssertNoError(out) } -func pingSourceCreateWithResources(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, sourceName string, schedule string, data string, sink string, sa string, requestcpu string, requestmm string, limitcpu string, limitmm string) { +func pingSourceCreateWithResources(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, sourceName string, schedule string, data string, sink string, sa string, requestcpu string, requestmm string, limitcpu string, limitmm string) { out := it.Kn().Run("source", "ping", "create", sourceName, "--schedule", schedule, "--data", data, "--sink", sink, "--service-account", sa, "--requests-cpu", requestcpu, "--requests-memory", requestmm, "--limits-cpu", limitcpu, "--limits-memory", limitmm) @@ -100,14 +100,14 @@ func pingSourceCreateWithResources(t *testing.T, it *integration.Test, r *integr r.AssertNoError(out) } -func pingSourceUpdateResources(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, sourceName string, requestcpu string, requestmm string, limitcpu string, limitmm string) { +func pingSourceUpdateResources(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, sourceName string, requestcpu string, requestmm string, limitcpu string, limitmm string) { out := it.Kn().Run("source", "ping", "update", sourceName, "--requests-cpu", requestcpu, "--requests-memory", requestmm, "--limits-cpu", limitcpu, "--limits-memory", limitmm) assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, sourceName, "updated", "namespace", it.Kn().Namespace())) r.AssertNoError(out) } -func verifyPingSourceDescribe(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, sourceName string, schedule string, data string, sink string) { +func verifyPingSourceDescribe(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, sourceName string, schedule string, data string, sink string) { out := it.Kn().Run("source", "ping", "describe", sourceName) assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, sourceName, schedule, data, sink)) r.AssertNoError(out) diff --git a/test/e2e/revision_test.go b/test/e2e/revision_test.go index 37b12f8993..e7e0de5b62 100644 --- a/test/e2e/revision_test.go +++ b/test/e2e/revision_test.go @@ -31,7 +31,7 @@ import ( func TestRevision(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { assert.NilError(t, it.Teardown()) @@ -70,7 +70,7 @@ func TestRevision(t *testing.T) { serviceDelete(t, it, r, "hello") } -func revisionListWithService(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceNames ...string) { +func revisionListWithService(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceNames ...string) { for _, svcName := range serviceNames { confGen := findConfigurationGeneration(t, it, r, svcName) out := it.Kn().Run("revision", "list", "-s", svcName) @@ -90,13 +90,13 @@ func revisionListWithService(t *testing.T, it *integration.Test, r *integration. } } -func revisionDelete(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, revName string) { +func revisionDelete(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, revName string) { out := it.Kn().Run("revision", "delete", revName) assert.Check(t, util.ContainsAll(out.Stdout, "Revision", revName, "deleted", "namespace", it.Kn().Namespace())) r.AssertNoError(out) } -func revisionMultipleDelete(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, existRevision1, existRevision2, nonexistRevision string) { +func revisionMultipleDelete(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, existRevision1, existRevision2, nonexistRevision string) { out := it.Kn().Run("revision", "list") r.AssertNoError(out) assert.Check(t, strings.Contains(out.Stdout, existRevision1), "Required revision1 does not exist") @@ -110,14 +110,14 @@ func revisionMultipleDelete(t *testing.T, it *integration.Test, r *integration.K assert.Check(t, util.ContainsAll(out.Stdout, "revisions.serving.knative.dev", nonexistRevision, "not found"), "Failed to get 'not found' error") } -func revisionDescribeWithPrintFlags(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, revName string) { +func revisionDescribeWithPrintFlags(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, revName string) { out := it.Kn().Run("revision", "describe", revName, "-o=name") r.AssertNoError(out) expectedName := fmt.Sprintf("revision.serving.knative.dev/%s", revName) assert.Equal(t, strings.TrimSpace(out.Stdout), expectedName) } -func findRevision(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string) string { +func findRevision(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string) string { out := it.Kn().Run("revision", "list", "-s", serviceName, "-o=jsonpath={.items[0].metadata.name}") r.AssertNoError(out) if strings.Contains(out.Stdout, "No resources") { @@ -126,7 +126,7 @@ func findRevision(t *testing.T, it *integration.Test, r *integration.KnRunResult return out.Stdout } -func findRevisionByGeneration(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string, generation int) string { +func findRevisionByGeneration(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string, generation int) string { maxGen := findConfigurationGeneration(t, it, r, serviceName) out := it.Kn().Run("revision", "list", "-s", serviceName, fmt.Sprintf("-o=jsonpath={.items[%d].metadata.name}", maxGen-generation)) @@ -137,7 +137,7 @@ func findRevisionByGeneration(t *testing.T, it *integration.Test, r *integration return out.Stdout } -func findConfigurationGeneration(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string) int { +func findConfigurationGeneration(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string) int { out := it.Kn().Run("revision", "list", "-s", serviceName, "-o=jsonpath={.items[0].metadata.labels.serving\\.knative\\.dev/configurationGeneration}") r.AssertNoError(out) if out.Stdout == "" { diff --git a/test/e2e/route_test.go b/test/e2e/route_test.go index 0439fe02b0..949e905f6c 100644 --- a/test/e2e/route_test.go +++ b/test/e2e/route_test.go @@ -30,7 +30,7 @@ import ( func TestRoute(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { assert.NilError(t, it.Teardown()) @@ -61,7 +61,7 @@ func TestRoute(t *testing.T) { serviceDelete(t, it, r, "hello") } -func routeList(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector) { +func routeList(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector) { out := it.Kn().Run("route", "list") expectedHeaders := []string{"NAME", "URL", "READY"} @@ -69,14 +69,14 @@ func routeList(t *testing.T, it *integration.Test, r *integration.KnRunResultCol r.AssertNoError(out) } -func routeListWithArgument(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, routeName string) { +func routeListWithArgument(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, routeName string) { out := it.Kn().Run("route", "list", routeName) assert.Check(t, util.ContainsAll(out.Stdout, routeName)) r.AssertNoError(out) } -func routeDescribe(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, routeName string) { +func routeDescribe(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, routeName string) { out := it.Kn().Run("route", "describe", routeName) assert.Check(t, util.ContainsAll(out.Stdout, @@ -84,7 +84,7 @@ func routeDescribe(t *testing.T, it *integration.Test, r *integration.KnRunResul r.AssertNoError(out) } -func routeDescribeWithPrintFlags(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, routeName string) { +func routeDescribeWithPrintFlags(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, routeName string) { out := it.Kn().Run("route", "describe", routeName, "-o=name") expectedName := fmt.Sprintf("route.serving.knative.dev/%s", routeName) @@ -92,7 +92,7 @@ func routeDescribeWithPrintFlags(t *testing.T, it *integration.Test, r *integrat r.AssertNoError(out) } -func routeListWithPrintFlags(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, names ...string) { +func routeListWithPrintFlags(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, names ...string) { out := it.Kn().Run("route", "list", "-o=jsonpath={.items[*].metadata.name}") assert.Check(t, util.ContainsAll(out.Stdout, names...)) r.AssertNoError(out) diff --git a/test/e2e/service_export_import_apply_test.go b/test/e2e/service_export_import_apply_test.go index 24564ee489..d882d3ede9 100644 --- a/test/e2e/service_export_import_apply_test.go +++ b/test/e2e/service_export_import_apply_test.go @@ -23,12 +23,14 @@ import ( "gotest.tools/assert" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" "knative.dev/pkg/ptr" "sigs.k8s.io/yaml" + "knative.dev/client/lib/test/integration" + + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" servingv1 "knative.dev/serving/pkg/apis/serving/v1" ) @@ -36,60 +38,64 @@ type expectedServiceOption func(*servingv1.Service) func TestServiceExportImportApply(t *testing.T) { t.Parallel() - test, err := NewE2eTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { - assert.NilError(t, test.Teardown()) + assert.NilError(t, it.Teardown()) }() - r := NewKnRunResultCollector(t) + r := integration.NewKnRunResultCollector(t) defer r.DumpIfFailed() t.Log("create service with byo revision") - test.serviceCreateWithOptions(t, r, "hello", "--revision-name", "rev1") + serviceCreateWithOptions(t, it, r, "hello", "--revision-name", "rev1") t.Log("export service and compare") - test.serviceExport(t, r, "hello", getSvc(withName("hello"), withRevisionName("hello-rev1"), withAnnotations()), "-o", "json") + serviceExport(t, it, r, "hello", getSvc(withName("hello"), withRevisionName("hello-rev1"), withAnnotations()), "-o", "json") t.Log("update service - add env variable") - test.serviceUpdateWithOptions(t, r, "hello", "--env", "key1=val1", "--revision-name", "rev2", "--no-lock-to-digest") - test.serviceExport(t, r, "hello", getSvc(withName("hello"), withRevisionName("hello-rev2"), withEnv("key1", "val1")), "-o", "json") - test.serviceExportWithRevisions(t, r, "hello", getSvcListWithOneRevision(), "--with-revisions", "-o", "yaml") + serviceUpdateWithOptions(t, it, r, "hello", "--env", "key1=val1", "--revision-name", "rev2", "--no-lock-to-digest") + serviceExport(t, it, r, "hello", getSvc(withName("hello"), withRevisionName("hello-rev2"), withEnv("key1", "val1")), "-o", "json") + serviceExportWithRevisions(t, it, r, "hello", getSvcListWithOneRevision(), "--with-revisions", "-o", "yaml") t.Log("update service with tag and split traffic") - test.serviceUpdateWithOptions(t, r, "hello", "--tag", "hello-rev1=candidate", "--traffic", "candidate=2%,@latest=98%") - test.serviceExportWithRevisions(t, r, "hello", getSvcListWithTags(), "--with-revisions", "-o", "yaml") + serviceUpdateWithOptions(t, it, r, "hello", "--tag", "hello-rev1=candidate", "--traffic", "candidate=2%,@latest=98%") + serviceExportWithRevisions(t, it, r, "hello", getSvcListWithTags(), "--with-revisions", "-o", "yaml") t.Log("update service - untag, add env variable and traffic split") - test.serviceUpdateWithOptions(t, r, "hello", "--untag", "candidate") - test.serviceUpdateWithOptions(t, r, "hello", "--env", "key2=val2", "--revision-name", "rev3", "--traffic", "hello-rev1=30,hello-rev2=30,hello-rev3=40") - test.serviceExportWithRevisions(t, r, "hello", getSvcListWOTags(), "--with-revisions", "-o", "yaml") + serviceUpdateWithOptions(t, it, r, "hello", "--untag", "candidate") + serviceUpdateWithOptions(t, it, r, "hello", "--env", "key2=val2", "--revision-name", "rev3", "--traffic", "hello-rev1=30,hello-rev2=30,hello-rev3=40") + serviceExportWithRevisions(t, it, r, "hello", getSvcListWOTags(), "--with-revisions", "-o", "yaml") } -func (test *e2eTest) serviceExport(t *testing.T, r *KnRunResultCollector, serviceName string, expService servingv1.Service, options ...string) { +// Private methods + +func serviceExport(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string, expService servingv1.Service, options ...string) { command := []string{"service", "export", serviceName} command = append(command, options...) - out := test.kn.Run(command...) - validateExportedService(t, out.Stdout, expService) + out := it.Kn().Run(command...) + validateExportedService(t, it, out.Stdout, expService) r.AssertNoError(out) } -func validateExportedService(t *testing.T, out string, expService servingv1.Service) { +func serviceExportWithRevisions(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string, expServiceList servingv1.ServiceList, options ...string) { + command := []string{"service", "export", serviceName} + command = append(command, options...) + out := it.Kn().Run(command...) + validateExportedServiceList(t, it, out.Stdout, expServiceList) + r.AssertNoError(out) +} + +// Private functions + +func validateExportedService(t *testing.T, it *integration.KnTest, out string, expService servingv1.Service) { actSvcJSON := servingv1.Service{} err := json.Unmarshal([]byte(out), &actSvcJSON) assert.NilError(t, err) assert.DeepEqual(t, &expService, &actSvcJSON) } -func (test *e2eTest) serviceExportWithRevisions(t *testing.T, r *KnRunResultCollector, serviceName string, expServiceList servingv1.ServiceList, options ...string) { - command := []string{"service", "export", serviceName} - command = append(command, options...) - out := test.kn.Run(command...) - validateExportedServiceList(t, out.Stdout, expServiceList) - r.AssertNoError(out) -} - -func validateExportedServiceList(t *testing.T, out string, expServiceList servingv1.ServiceList) { +func validateExportedServiceList(t *testing.T, it *integration.KnTest, out string, expServiceList servingv1.ServiceList) { actYaml := servingv1.ServiceList{} err := yaml.Unmarshal([]byte(out), &actYaml) assert.NilError(t, err) @@ -108,7 +114,7 @@ func getSvc(options ...expectedServiceOption) servingv1.Service { Containers: []corev1.Container{ { Name: "user-container", - Image: KnDefaultTestImage, + Image: integration.KnDefaultTestImage, Resources: corev1.ResourceRequirements{}, ReadinessProbe: &corev1.Probe{ SuccessThreshold: int32(1), diff --git a/test/e2e/service_options_test.go b/test/e2e/service_options_test.go index 9810a115fb..cf75a220d4 100644 --- a/test/e2e/service_options_test.go +++ b/test/e2e/service_options_test.go @@ -35,7 +35,7 @@ import ( func TestServiceOptions(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { assert.NilError(t, it.Teardown()) @@ -57,7 +57,7 @@ func TestServiceOptions(t *testing.T) { t.Log("update concurrency options with invalid values for service") out := it.Kn().Run("service", "update", "svc1", "--concurrency-limit", "-1", "--concurrency-target", "0") r.AssertError(out) - assert.Check(t, it, util.ContainsAll(out.Stderr, "invalid")) + assert.Check(t, util.ContainsAll(out.Stderr, "invalid")) t.Log("returns steady concurrency options for service") validateServiceConcurrencyLimit(t, it, r, "svc1", "300") @@ -112,77 +112,77 @@ func TestServiceOptions(t *testing.T) { validateUserId(t, it, r, "svc6", uid+1) } -func serviceCreateWithOptions(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string, options ...string) { +func serviceCreateWithOptions(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string, options ...string) { command := []string{"service", "create", serviceName, "--image", integration.KnDefaultTestImage} command = append(command, options...) out := it.Kn().Run(command...) - assert.Check(t, it, util.ContainsAll(out.Stdout, "service", serviceName, "Creating", "namespace", it.Kn().Namespace(), "Ready")) + assert.Check(t, util.ContainsAll(out.Stdout, "service", serviceName, "Creating", "namespace", it.Kn().Namespace(), "Ready")) r.AssertNoError(out) } -func validateServiceConcurrencyLimit(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName, concurrencyLimit string) { +func validateServiceConcurrencyLimit(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName, concurrencyLimit string) { jsonpath := "jsonpath={.items[0].spec.template.spec.containerConcurrency}" out := it.Kn().Run("service", "list", serviceName, "-o", jsonpath) - assert.Equal(t, it, out.Stdout, concurrencyLimit) + assert.Equal(t, out.Stdout, concurrencyLimit) r.AssertNoError(out) } -func validateServiceConcurrencyTarget(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName, concurrencyTarget string) { +func validateServiceConcurrencyTarget(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName, concurrencyTarget string) { jsonpath := "jsonpath={.items[0].spec.template.metadata.annotations.autoscaling\\.knative\\.dev/target}" out := it.Kn().Run("service", "list", serviceName, "-o", jsonpath) - assert.Equal(t, it, out.Stdout, concurrencyTarget) + assert.Equal(t, out.Stdout, concurrencyTarget) r.AssertNoError(out) } -func validateAutoscaleWindow(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName, window string) { +func validateAutoscaleWindow(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName, window string) { jsonpath := "jsonpath={.items[0].spec.template.metadata.annotations.autoscaling\\.knative\\.dev/window}" out := it.Kn().Run("service", "list", serviceName, "-o", jsonpath) - assert.Equal(t, it, out.Stdout, window) + assert.Equal(t, out.Stdout, window) r.AssertNoError(out) } -func validateServiceMinScale(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName, minScale string) { +func validateServiceMinScale(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName, minScale string) { jsonpath := "jsonpath={.items[0].spec.template.metadata.annotations.autoscaling\\.knative\\.dev/minScale}" out := it.Kn().Run("service", "list", serviceName, "-o", jsonpath) - assert.Equal(t, it, out.Stdout, minScale) + assert.Equal(t, out.Stdout, minScale) r.AssertNoError(out) } -func validateServiceMaxScale(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName, maxScale string) { +func validateServiceMaxScale(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName, maxScale string) { jsonpath := "jsonpath={.items[0].spec.template.metadata.annotations.autoscaling\\.knative\\.dev/maxScale}" out := it.Kn().Run("service", "list", serviceName, "-o", jsonpath) - assert.Equal(t, it, out.Stdout, maxScale) + assert.Equal(t, out.Stdout, maxScale) r.AssertNoError(out) } -func validateServiceAnnotations(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string, annotations map[string]string) { +func validateServiceAnnotations(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string, annotations map[string]string) { metadataAnnotationsJsonpathFormat := "jsonpath={.metadata.annotations.%s}" templateAnnotationsJsonpathFormat := "jsonpath={.spec.template.metadata.annotations.%s}" for k, v := range annotations { - out := it.Kn().Run("service", "describe", serviceName, "-o", fmt.Sprintf(metadataAnnotationsJsonpathFormat, it, k)) - assert.Equal(t, it, v, out.Stdout) + out := it.Kn().Run("service", "describe", serviceName, "-o", fmt.Sprintf(metadataAnnotationsJsonpathFormat, k)) + assert.Equal(t, v, out.Stdout) r.AssertNoError(out) - out = it.Kn().Run("service", "describe", serviceName, "-o", fmt.Sprintf(templateAnnotationsJsonpathFormat, it, k)) - assert.Equal(t, it, v, out.Stdout) + out = it.Kn().Run("service", "describe", serviceName, "-o", fmt.Sprintf(templateAnnotationsJsonpathFormat, k)) + assert.Equal(t, v, out.Stdout) r.AssertNoError(out) } } -func validateContainerField(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName, field, expected string) { +func validateContainerField(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName, field, expected string) { jsonpath := fmt.Sprintf("jsonpath={.items[0].spec.template.spec.containers[0].%s}", field) out := it.Kn().Run("service", "list", serviceName, "-o", jsonpath) - assert.Equal(t, it, out.Stdout, expected) + assert.Equal(t, out.Stdout, expected) r.AssertNoError(out) } -func validateUserId(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string, uid int64) { +func validateUserId(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string, uid int64) { out := it.Kn().Run("service", "describe", serviceName, "-ojson") data := json.NewDecoder(strings.NewReader(out.Stdout)) data.UseNumber() var service servingv1.Service err := data.Decode(&service) assert.NilError(t, err) - assert.Equal(t, it, *service.Spec.Template.Spec.Containers[0].SecurityContext.RunAsUser, uid) + assert.Equal(t, *service.Spec.Template.Spec.Containers[0].SecurityContext.RunAsUser, uid) } diff --git a/test/e2e/service_test.go b/test/e2e/service_test.go index 99871b361b..a82aa4ffff 100644 --- a/test/e2e/service_test.go +++ b/test/e2e/service_test.go @@ -31,7 +31,7 @@ import ( func TestService(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { assert.NilError(t, it.Teardown()) @@ -60,7 +60,7 @@ func TestService(t *testing.T) { serviceCreatePrivateUpdatePublic(t, it, r, "hello-private-public") } -func serviceCreatePrivate(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string) { +func serviceCreatePrivate(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string) { out := it.Kn().Run("service", "create", serviceName, "--image", integration.KnDefaultTestImage, "--cluster-local") r.AssertNoError(out) @@ -71,7 +71,7 @@ func serviceCreatePrivate(t *testing.T, it *integration.Test, r *integration.KnR assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, serving.VisibilityLabelKey, serving.VisibilityClusterLocal)) } -func serviceCreatePrivateUpdatePublic(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string) { +func serviceCreatePrivateUpdatePublic(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string) { out := it.Kn().Run("service", "create", serviceName, "--image", integration.KnDefaultTestImage, "--cluster-local") r.AssertNoError(out) @@ -91,7 +91,7 @@ func serviceCreatePrivateUpdatePublic(t *testing.T, it *integration.Test, r *int assert.Check(t, util.ContainsNone(out.Stdout, serving.VisibilityLabelKey, serving.VisibilityClusterLocal)) } -func serviceCreateDuplicate(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string) { +func serviceCreateDuplicate(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string) { out := it.Kn().Run("service", "list", serviceName) r.AssertNoError(out) assert.Check(t, strings.Contains(out.Stdout, serviceName), "The service does not exist yet") @@ -101,7 +101,7 @@ func serviceCreateDuplicate(t *testing.T, it *integration.Test, r *integration.K assert.Check(t, util.ContainsAll(out.Stderr, "the service already exists")) } -func serviceDescribeWithPrintFlags(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string) { +func serviceDescribeWithPrintFlags(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string) { out := it.Kn().Run("service", "describe", serviceName, "-o=name") r.AssertNoError(out) @@ -109,7 +109,7 @@ func serviceDescribeWithPrintFlags(t *testing.T, it *integration.Test, r *integr assert.Equal(t, strings.TrimSpace(out.Stdout), expectedName) } -func serviceDeleteNonexistent(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string) { +func serviceDeleteNonexistent(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string) { out := it.Kn().Run("service", "list", serviceName) r.AssertNoError(out) assert.Check(t, !strings.Contains(out.Stdout, serviceName), "The service exists") @@ -119,7 +119,7 @@ func serviceDeleteNonexistent(t *testing.T, it *integration.Test, r *integration assert.Check(t, util.ContainsAll(out.Stdout, "hello", "not found"), "Failed to get 'not found' error") } -func serviceMultipleDelete(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, existService, nonexistService string) { +func serviceMultipleDelete(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, existService, nonexistService string) { out := it.Kn().Run("service", "list") r.AssertNoError(out) assert.Check(t, strings.Contains(out.Stdout, existService), "The service ", existService, " does not exist (but is expected to exist)") diff --git a/test/e2e/sinkprefix_test.go b/test/e2e/sinkprefix_test.go index 141fecaf0e..04c079596f 100644 --- a/test/e2e/sinkprefix_test.go +++ b/test/e2e/sinkprefix_test.go @@ -59,7 +59,7 @@ func (tc *sinkprefixTestConfig) teardown() { func TestSinkPrefixConfig(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { assert.NilError(t, it.Teardown()) @@ -86,7 +86,7 @@ func TestSinkPrefixConfig(t *testing.T) { pingSourceDelete(t, it, r, "testpingsource0") } -func pingSourceCreateWithConfig(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, sourceName string, schedule string, data string, sink string, config string) { +func pingSourceCreateWithConfig(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, sourceName string, schedule string, data string, sink string, config string) { out := it.Kn().Run("source", "ping", "create", sourceName, "--schedule", schedule, "--data", data, "--sink", sink, "--config", config) assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "created", "namespace", it.Kn().Namespace())) diff --git a/test/e2e/source_apiserver_test.go b/test/e2e/source_apiserver_test.go index 2e57ef93c8..ab881bf3e6 100644 --- a/test/e2e/source_apiserver_test.go +++ b/test/e2e/source_apiserver_test.go @@ -38,7 +38,7 @@ const ( func TestSourceApiServer(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { err1 := tearDownForSourceApiServer(t, it) @@ -85,25 +85,25 @@ func TestSourceApiServer(t *testing.T) { // TODO(navidshaikh): Verify the source's status with synchronous create/update } -func apiServerSourceCreate(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, sourceName string, resources string, sa string, sink string) { +func apiServerSourceCreate(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, sourceName string, resources string, sa string, sink string) { out := it.Kn().Run("source", "apiserver", "create", sourceName, "--resource", resources, "--service-account", sa, "--sink", sink) r.AssertNoError(out) assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "apiserver", "source", sourceName, "created", "namespace", it.Kn().Namespace())) } -func apiServerSourceCreateMissingSink(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, sourceName string, resources string, sa string, sink string) { +func apiServerSourceCreateMissingSink(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, sourceName string, resources string, sa string, sink string) { out := it.Kn().Run("source", "apiserver", "create", sourceName, "--resource", resources, "--service-account", sa, "--sink", sink) r.AssertError(out) assert.Check(t, util.ContainsAll(out.Stderr, "services.serving.knative.dev", "not found")) } -func apiServerSourceDelete(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, sourceName string) { +func apiServerSourceDelete(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, sourceName string) { out := it.Kn().Run("source", "apiserver", "delete", sourceName) r.AssertNoError(out) assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "apiserver", "source", sourceName, "deleted", "namespace", it.Kn().Namespace())) } -func setupForSourceApiServer(t *testing.T, it *integration.Test) { +func setupForSourceApiServer(t *testing.T, it *integration.KnTest) { _, err := integration.NewKubectl(it.Kn().Namespace()).Run("create", "serviceaccount", testServiceAccount) assert.NilError(t, err) @@ -119,7 +119,7 @@ func setupForSourceApiServer(t *testing.T, it *integration.Test) { assert.NilError(t, err) } -func tearDownForSourceApiServer(t *testing.T, it *integration.Test) error { +func tearDownForSourceApiServer(t *testing.T, it *integration.KnTest) error { saCmd := []string{"delete", "serviceaccount", testServiceAccount} _, err := integration.NewKubectl(it.Kn().Namespace()).Run(saCmd...) if err != nil { @@ -140,13 +140,13 @@ func tearDownForSourceApiServer(t *testing.T, it *integration.Test) error { return nil } -func apiServerSourceUpdateSink(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, sourceName string, sink string) { +func apiServerSourceUpdateSink(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, sourceName string, sink string) { out := it.Kn().Run("source", "apiserver", "update", sourceName, "--sink", sink) r.AssertNoError(out) assert.Check(t, util.ContainsAll(out.Stdout, sourceName, "updated", "namespace", it.Kn().Namespace())) } -func getResourceFieldsWithJSONPath(t *testing.T, it *integration.Test, resource, name, jsonpath string) (string, error) { +func getResourceFieldsWithJSONPath(t *testing.T, it *integration.KnTest, resource, name, jsonpath string) (string, error) { out, err := integration.NewKubectl(it.Kn().Namespace()).Run("get", resource, name, "-o", jsonpath, "-n", it.Kn().Namespace()) if err != nil { return "", err diff --git a/test/e2e/source_binding_test.go b/test/e2e/source_binding_test.go index 704222a800..5eceace265 100644 --- a/test/e2e/source_binding_test.go +++ b/test/e2e/source_binding_test.go @@ -28,7 +28,7 @@ import ( func TestSourceBinding(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { assert.NilError(t, it.Teardown()) @@ -55,19 +55,19 @@ func TestSourceBinding(t *testing.T) { assert.Equal(t, out, "testsvc1") } -func sourceBindingCreate(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, bindingName string, subject string, sink string) { +func sourceBindingCreate(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, bindingName string, subject string, sink string) { out := it.Kn().Run("source", "binding", "create", bindingName, "--subject", subject, "--sink", sink) r.AssertNoError(out) assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "Sink", "binding", bindingName, "created", "namespace", it.Kn().Namespace())) } -func sourceBindingDelete(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, bindingName string) { +func sourceBindingDelete(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, bindingName string) { out := it.Kn().Run("source", "binding", "delete", bindingName) r.AssertNoError(out) assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "Sink", "binding", bindingName, "deleted", "namespace", it.Kn().Namespace())) } -func sourceBindingUpdate(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, bindingName string, subject string, sink string) { +func sourceBindingUpdate(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, bindingName string, subject string, sink string) { out := it.Kn().Run("source", "binding", "update", bindingName, "--subject", subject, "--sink", sink) r.AssertNoError(out) assert.Check(t, util.ContainsAll(out.Stdout, bindingName, "updated", "namespace", it.Kn().Namespace())) diff --git a/test/e2e/source_list_test.go b/test/e2e/source_list_test.go index 917a830b76..03fb49e724 100644 --- a/test/e2e/source_list_test.go +++ b/test/e2e/source_list_test.go @@ -28,7 +28,7 @@ import ( func TestSourceListTypes(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { assert.NilError(t, it.Teardown()) @@ -49,7 +49,7 @@ func TestSourceListTypes(t *testing.T) { func TestSourceList(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { assert.NilError(t, it.Teardown()) @@ -66,14 +66,14 @@ func TestSourceList(t *testing.T) { // non empty list case is tested in test/e2e/source_apiserver_it.go where source setup is present } -func sourceListTypes(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, args ...string) string { +func sourceListTypes(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, args ...string) string { cmd := append([]string{"source", "list-types"}, args...) out := it.Kn().Run(cmd...) r.AssertNoError(out) return out.Stdout } -func sourceList(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, args ...string) string { +func sourceList(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, args ...string) string { cmd := append([]string{"source", "list"}, args...) out := it.Kn().Run(cmd...) r.AssertNoError(out) diff --git a/test/e2e/traffic_split_test.go b/test/e2e/traffic_split_test.go index bcf3d3b049..ed8fee4674 100644 --- a/test/e2e/traffic_split_test.go +++ b/test/e2e/traffic_split_test.go @@ -61,7 +61,7 @@ func splitTargets(s, separator string, partsCount int) ([]string, error) { // formatActualTargets takes the traffic targets string received after jsonpath operation and converts // them into []TargetFields for comparison -func formatActualTargets(t *testing.T, it *integration.Test, actualTargets []string) (formattedTargets []TargetFields) { +func formatActualTargets(t *testing.T, it *integration.KnTest, actualTargets []string) (formattedTargets []TargetFields) { for _, each := range actualTargets { each := strings.TrimSuffix(each, targetFieldsSeparator) fields, err := splitTargets(each, targetFieldsSeparator, targetFieldsLength) @@ -78,7 +78,7 @@ func formatActualTargets(t *testing.T, it *integration.Test, actualTargets []str // TestTrafficSplitSuite runs different e2e tests for service traffic splitting and verifies the traffic targets from service status func TestTrafficSplit(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { assert.NilError(t, it.Teardown()) @@ -412,7 +412,7 @@ func TestTrafficSplit(t *testing.T) { ) } -func verifyTargets(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string, expectedTargets []TargetFields) { +func verifyTargets(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string, expectedTargets []TargetFields) { out := serviceDescribeWithJsonPath(t, it, r, serviceName, targetsJsonPath) assert.Check(t, out != "") actualTargets, err := splitTargets(out, targetsSeparator, len(expectedTargets)) @@ -424,13 +424,13 @@ func verifyTargets(t *testing.T, it *integration.Test, r *integration.KnRunResul } } -func serviceDescribeWithJsonPath(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName, jsonpath string) string { +func serviceDescribeWithJsonPath(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName, jsonpath string) string { out := it.Kn().Run("service", "describe", serviceName, "-o", jsonpath) r.AssertNoError(out) return out.Stdout } -func serviceUpdateWithOptions(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, serviceName string, options ...string) { +func serviceUpdateWithOptions(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, serviceName string, options ...string) { command := []string{"service", "update", serviceName} command = append(command, options...) out := it.Kn().Run(command...) diff --git a/test/e2e/trigger_inject_broker_test.go b/test/e2e/trigger_inject_broker_test.go index 30490946b7..f719e49f0f 100644 --- a/test/e2e/trigger_inject_broker_test.go +++ b/test/e2e/trigger_inject_broker_test.go @@ -28,7 +28,7 @@ import ( func TestInjectBrokerTrigger(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { assert.NilError(t, it.Teardown()) @@ -56,7 +56,7 @@ func TestInjectBrokerTrigger(t *testing.T) { assert.Check(t, util.ContainsAllIgnoreCase(out.Stderr, "broker", "name", "'default'", "--inject-broker", "flag")) } -func triggerCreateWithInject(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, name string, sinksvc string, filters []string) { +func triggerCreateWithInject(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, name string, sinksvc string, filters []string) { args := []string{"trigger", "create", name, "--broker", "default", "--inject-broker", "--sink", "svc:" + sinksvc} for _, v := range filters { args = append(args, "--filter", v) diff --git a/test/e2e/trigger_test.go b/test/e2e/trigger_test.go index dee9591758..bcfdb31830 100644 --- a/test/e2e/trigger_test.go +++ b/test/e2e/trigger_test.go @@ -31,7 +31,7 @@ import ( func TestBrokerTrigger(t *testing.T) { t.Parallel() - it, err := integration.NewIntegrationTest() + it, err := integration.NewKnTest() assert.NilError(t, err) defer func() { assert.NilError(t, it.Teardown()) @@ -60,13 +60,13 @@ func TestBrokerTrigger(t *testing.T) { verifyTriggerNotfound(t, it, r, "deltrigger") t.Log("create a trigger with filters and remove them one by one") - test.triggerCreate(t, r, "filtertrigger", "sinksvc0", []string{"foo=bar", "source=ping"}) - test.verifyTriggerDescribe(t, r, "filtertrigger", "default", "sinksvc0", []string{"foo", "bar", "source", "ping"}) - test.triggerUpdate(t, r, "filtertrigger", "foo-", "sinksvc0") - test.verifyTriggerDescribe(t, r, "filtertrigger", "default", "sinksvc0", []string{"source", "ping"}) - test.triggerUpdate(t, r, "filtertrigger", "source-", "sinksvc0") - test.verifyTriggerDescribe(t, r, "filtertrigger", "default", "sinksvc0", nil) - test.triggerDelete(t, r, "filtertrigger") + triggerCreate(t, it, r, "filtertrigger", "sinksvc0", []string{"foo=bar", "source=ping"}) + verifyTriggerDescribe(t, it, r, "filtertrigger", "default", "sinksvc0", []string{"foo", "bar", "source", "ping"}) + triggerUpdate(t, it, r, "filtertrigger", "foo-", "sinksvc0") + verifyTriggerDescribe(t, it, r, "filtertrigger", "default", "sinksvc0", []string{"source", "ping"}) + triggerUpdate(t, it, r, "filtertrigger", "source-", "sinksvc0") + verifyTriggerDescribe(t, it, r, "filtertrigger", "default", "sinksvc0", nil) + triggerDelete(t, it, r, "filtertrigger") t.Log("create a trigger, describe and update it") triggerCreate(t, it, r, "updtrigger", "sinksvc0", []string{"a=b"}) @@ -79,15 +79,16 @@ func TestBrokerTrigger(t *testing.T) { triggerCreateMissingSink(t, it, r, "errtrigger", "notfound") } -func unlableNamespaceForDefaultBroker(t *testing.T, it *integration.Test) { +// Private functions + +func unlableNamespaceForDefaultBroker(t *testing.T, it *integration.KnTest) { _, err := integration.Kubectl{}.Run("label", "namespace", it.Kn().Namespace(), "knative-eventing-injection-") - if err != nil { t.Fatalf("Error executing 'kubectl label namespace %s knative-eventing-injection-'. Error: %s", it.Kn().Namespace(), err.Error()) } } -func lableNamespaceForDefaultBroker(t *testing.T, it *integration.Test) error { +func lableNamespaceForDefaultBroker(t *testing.T, it *integration.KnTest) error { _, err := integration.Kubectl{}.Run("label", "namespace", it.Kn().Namespace(), "knative-eventing-injection=enabled") if err != nil { @@ -104,7 +105,7 @@ func lableNamespaceForDefaultBroker(t *testing.T, it *integration.Test) error { }) } -func triggerCreate(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, name string, sinksvc string, filters []string) { +func triggerCreate(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, name string, sinksvc string, filters []string) { args := []string{"trigger", "create", name, "--broker", "default", "--sink", "svc:" + sinksvc} if len(filters) > 0 { for _, v := range filters { @@ -116,31 +117,31 @@ func triggerCreate(t *testing.T, it *integration.Test, r *integration.KnRunResul assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "Trigger", name, "created", "namespace", it.Kn().Namespace())) } -func triggerCreateMissingSink(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, name string, sinksvc string) { +func triggerCreateMissingSink(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, name string, sinksvc string) { out := it.Kn().Run("trigger", "create", name, "--broker", "default", "--sink", "svc:"+sinksvc) r.AssertError(out) assert.Check(t, util.ContainsAll(out.Stderr, "services.serving.knative.dev", "not found")) } -func triggerDelete(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, name string) { +func triggerDelete(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, name string) { out := it.Kn().Run("trigger", "delete", name) r.AssertNoError(out) assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "Trigger", name, "deleted", "namespace", it.Kn().Namespace())) } -func triggerUpdate(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, name string, filter string, sinksvc string) { +func triggerUpdate(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, name string, filter string, sinksvc string) { out := it.Kn().Run("trigger", "update", name, "--filter", filter, "--sink", "svc:"+sinksvc) r.AssertNoError(out) assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "Trigger", name, "updated", "namespace", it.Kn().Namespace())) } -func verifyTriggerList(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, triggers ...string) { +func verifyTriggerList(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, triggers ...string) { out := it.Kn().Run("trigger", "list") r.AssertNoError(out) assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, triggers...)) } -func verifyTriggerDescribe(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, name string, broker string, sink string, filters []string) { +func verifyTriggerDescribe(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, name string, broker string, sink string, filters []string) { out := it.Kn().Run("trigger", "describe", name) r.AssertNoError(out) if len(filters) > 0 { @@ -151,7 +152,7 @@ func verifyTriggerDescribe(t *testing.T, it *integration.Test, r *integration.Kn assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, name, broker, sink)) } -func verifyTriggerNotfound(t *testing.T, it *integration.Test, r *integration.KnRunResultCollector, name string) { +func verifyTriggerNotfound(t *testing.T, it *integration.KnTest, r *integration.KnRunResultCollector, name string) { out := it.Kn().Run("trigger", "describe", name) r.AssertError(out) assert.Check(t, util.ContainsAll(out.Stderr, name, "not found"))