From 08ddd6ffbf288f24d363c6f8233ae0851f241041 Mon Sep 17 00:00:00 2001 From: slinkydeveloper Date: Fri, 30 Aug 2019 18:27:40 +0200 Subject: [PATCH 1/4] E2e test wip --- Gopkg.lock | 78 ++++++++++++++++++++++++++++++++++++++++ test/e2e/faas_test.go | 82 +++++++++++++++++++++++++++++++++++++++++++ test/e2e/main_test.go | 10 ++++++ test/util.go | 26 ++++++++++++++ 4 files changed, 196 insertions(+) create mode 100644 test/e2e/faas_test.go create mode 100644 test/e2e/main_test.go create mode 100644 test/util.go diff --git a/Gopkg.lock b/Gopkg.lock index b7e480ed..d169505a 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -49,6 +49,14 @@ revision = "5e7a399d8bbf4953ab0c8e3167d7fd535fd74ce1" version = "v13.0.0" +[[projects]] + digest = "1:75d2b55b13298745ec068057251d05d65bbae0a668201fe45ad6986551a55601" + name = "github.com/BurntSushi/toml" + packages = ["."] + pruneopts = "NT" + revision = "3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005" + version = "v0.3.1" + [[projects]] digest = "1:0a111edd8693fd977f42a0c4f199a0efb13c20aec9da99ad8830c7bb6a87e8d6" name = "github.com/PuerkitoBio/purell" @@ -401,6 +409,14 @@ revision = "7c29201646fa3de8506f701213473dd407f19646" version = "v0.3.7" +[[projects]] + digest = "1:406338ad39ab2e37b7f4452906442a3dbf0eb3379dd1f06aafb5c07e769a5fbb" + name = "github.com/inconshreveable/mousetrap" + packages = ["."] + pruneopts = "NT" + revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" + version = "v1.0" + [[projects]] digest = "1:1234e31f3de67447e344dabcdf72c4588d31b8eed2d28f1889377ec006a086a9" name = "github.com/jmespath/go-jmespath" @@ -436,6 +452,14 @@ revision = "a59dae6f326057211f43f7c2d1414a9fd821b8aa" version = "v0.8.0" +[[projects]] + digest = "1:58999a98719fddbac6303cb17e8d85b945f60b72f48e3a2df6b950b97fa926f1" + name = "github.com/konsorten/go-windows-terminal-sequences" + packages = ["."] + pruneopts = "NT" + revision = "f55edac94c9bbba5d6182a4be46d86a2c9b5b50e" + version = "v1.0.2" + [[projects]] branch = "master" digest = "1:5abd2595ba85b83e66f26ac8e89605dd334f0bfe3c455c1bf25a6a176a4fe836" @@ -472,6 +496,14 @@ revision = "c12348ce28de40eed0136aa2b644d0ee0650e56c" version = "v1.0.1" +[[projects]] + digest = "1:f9f72e583aaacf1d1ac5d6121abd4afd3c690baa9e14e1d009df26bf831ba347" + name = "github.com/mitchellh/go-homedir" + packages = ["."] + pruneopts = "NT" + revision = "af06845cf3004701891bf4fdb884bfe4920b3727" + version = "v1.1.0" + [[projects]] digest = "1:2f42fa12d6911c7b7659738758631bec870b7e9b4c6be5444f963cdcfccc191f" name = "github.com/modern-go/concurrent" @@ -492,11 +524,20 @@ digest = "1:fe3c97fb1956829a81d7b8221b4710c40d6dae2c6c3b4d222db5b7f96c975d99" name = "github.com/operator-framework/operator-sdk" packages = [ + "internal/pkg/scaffold", + "internal/pkg/scaffold/input", + "internal/pkg/scaffold/internal/deps", + "internal/util/fileutil", + "internal/util/k8sutil", + "internal/util/projutil", + "internal/util/yamlutil", "pkg/k8sutil", "pkg/leader", "pkg/log/zap", "pkg/metrics", "pkg/restmapper", + "pkg/test", + "pkg/test/e2eutil", "version", ] pruneopts = "NT" @@ -535,6 +576,14 @@ revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4" version = "v0.8.1" +[[projects]] + digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" + name = "github.com/pmezard/go-difflib" + packages = ["difflib"] + pruneopts = "NT" + revision = "792786c7400a136282c1664665ae0a8db921c6c2" + version = "v1.0.0" + [[projects]] digest = "1:e2fde2e6d46505f0d91d6d350410ca82f382870c90d6b05227302f45f78828a7" name = "github.com/prometheus/client_golang" @@ -590,6 +639,14 @@ revision = "438578804ca6f31be148c27683afc419ce47c06e" version = "v1.3.0" +[[projects]] + digest = "1:efe8ddffa78bddbd1d826faf622cca77dbf7ddc72df04077d69a688cac657148" + name = "github.com/sirupsen/logrus" + packages = ["."] + pruneopts = "NT" + revision = "839c75faf7f98a33d445d181f3018b5c3409a45e" + version = "v1.4.2" + [[projects]] digest = "1:49b6e0d199dc20969bf7c9d14647313e1dd1b102178fad4ca999d8a9584edfab" name = "github.com/spf13/afero" @@ -601,6 +658,14 @@ revision = "588a75ec4f32903aa5e39a2619ba6a4631e28424" version = "v1.2.2" +[[projects]] + digest = "1:37a91e5093cb260946900c75198c293f3439187e43f48e1a3ae10b4aa55bd7ad" + name = "github.com/spf13/cobra" + packages = ["."] + pruneopts = "NT" + revision = "f2b07da1e2c38d5f12845a4f607e2e1018cbb1f5" + version = "v0.0.5" + [[projects]] digest = "1:9d8420bbf131d1618bde6530af37c3799340d3762cc47210c1d9532a4c3a2779" name = "github.com/spf13/pflag" @@ -609,6 +674,14 @@ revision = "298182f68c66c05229eb03ac171abe6e309ee79a" version = "v1.0.3" +[[projects]] + digest = "1:b1eb7870c859801cf1b3d92ce7326dda6abb90e5ff4d6bcee3d0c54e8d6acfec" + name = "github.com/stretchr/testify" + packages = ["assert"] + pruneopts = "NT" + revision = "221dbe5ed46703ee255b1da0dec05086f5035f62" + version = "v1.4.0" + [[projects]] digest = "1:0b30d1cfbc7b4a319c1dbfdc81388257ef36e044b583450798511d1a3d8f9330" name = "github.com/tektoncd/pipeline" @@ -982,6 +1055,7 @@ packages = [ "pkg/apis/apiextensions", "pkg/apis/apiextensions/v1beta1", + "pkg/client/clientset/clientset/scheme", ] pruneopts = "NT" revision = "0fe22c71c47604641d9aa352c785b7912c200562" @@ -1046,6 +1120,7 @@ name = "k8s.io/client-go" packages = [ "discovery", + "discovery/cached", "dynamic", "informers", "informers/admissionregistration", @@ -1383,8 +1458,11 @@ "github.com/operator-framework/operator-sdk/pkg/log/zap", "github.com/operator-framework/operator-sdk/pkg/metrics", "github.com/operator-framework/operator-sdk/pkg/restmapper", + "github.com/operator-framework/operator-sdk/pkg/test", + "github.com/operator-framework/operator-sdk/pkg/test/e2eutil", "github.com/operator-framework/operator-sdk/version", "github.com/spf13/pflag", + "github.com/stretchr/testify/assert", "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1", "k8s.io/api/core/v1", "k8s.io/apimachinery/pkg/api/errors", diff --git a/test/e2e/faas_test.go b/test/e2e/faas_test.go new file mode 100644 index 00000000..53944a29 --- /dev/null +++ b/test/e2e/faas_test.go @@ -0,0 +1,82 @@ +package e2e + +import ( + goctx "context" + "github.com/openshift-cloud-functions/js-function-operator/pkg/apis" + jsfunction "github.com/openshift-cloud-functions/js-function-operator/pkg/apis/faas/v1alpha1" + framework "github.com/operator-framework/operator-sdk/pkg/test" + "github.com/operator-framework/operator-sdk/pkg/test/e2eutil" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "testing" + "time" +) + +const OPERATOR_NAME string = "js-function-operator" + +var ( + functionName = "test-function" + functionSrc = ` + module.exports = context => { + return "ok"; + };` + retryInterval = time.Second * 5 + timeout = time.Second * 60 + cleanupRetryInterval = time.Second * 1 + cleanupTimeout = time.Second * 5 +) + +func TestJsFaas(t *testing.T) { + // Add CRDs + jsFunctionList := &jsfunction.JSFunctionList{} + err := framework.AddToFrameworkScheme(apis.AddToScheme, jsFunctionList) + if err != nil { + t.Fatalf("failed to add custom resource scheme to framework: %v", err) + } + t.Log("Added CRDs") + + // Setup test framework + ctx := framework.NewTestCtx(t) + defer ctx.Cleanup() + t.Log("Test Framework context ready") + + // Initialize cluster resources + err = ctx.InitializeClusterResources(&framework.CleanupOptions{TestContext: ctx, Timeout: cleanupTimeout, RetryInterval: cleanupRetryInterval}) + if err != nil { + t.Fatalf("failed to initialize cluster resources: %v", err) + } + t.Log("Initialized cluster resources") + + namespace, err := ctx.GetNamespace() + if err != nil { + t.Fatal(err) + } + f := framework.Global + err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, OPERATOR_NAME, 1, retryInterval, timeout) + if err != nil { + t.Fatal(err) + } + t.Log("Operator ready") + + if err = testRunFunction(t, f, ctx, namespace); err != nil { + t.Fatal(err) + } + +} + +func testRunFunction(t *testing.T, f *framework.Framework, ctx *framework.TestCtx, namespace string) error { + exampleJs := &jsfunction.JSFunction{ + ObjectMeta: metav1.ObjectMeta{ + Name: functionName, + Namespace: namespace, + }, + Spec: jsfunction.JSFunctionSpec{ + Func: functionSrc, + }, + } + + err := f.Client.Create(goctx.TODO(), exampleJs, &framework.CleanupOptions{TestContext: ctx}) + if err != nil { + t.Fatal(err) + } + +} diff --git a/test/e2e/main_test.go b/test/e2e/main_test.go new file mode 100644 index 00000000..b87e15d8 --- /dev/null +++ b/test/e2e/main_test.go @@ -0,0 +1,10 @@ +package e2e + +import ( + f "github.com/operator-framework/operator-sdk/pkg/test" + "testing" +) + +func TestMain(m *testing.M) { + f.MainEntry(m) +} diff --git a/test/util.go b/test/util.go new file mode 100644 index 00000000..8b989196 --- /dev/null +++ b/test/util.go @@ -0,0 +1,26 @@ +package test + +import ( + "github.com/stretchr/testify/assert" + "io/ioutil" + "net/http" + "testing" +) + +func AssertGetRequest(t *testing.T, url string, expectedStatusCode int, expectedBody []byte) { + res, err := http.Get(url) + if err != nil { + assert.Fail(t, err.Error()) + return + } + + assert.Equal(t, expectedStatusCode, res.StatusCode) + + b, err := ioutil.ReadAll(res.Body) + if err != nil { + assert.Fail(t, err.Error()) + return + } + + assert.Equal(t, expectedBody, b) +} From c9494c752d72752be8db92fe77ec4e39651e24cc Mon Sep 17 00:00:00 2001 From: slinkydeveloper Date: Mon, 2 Sep 2019 11:16:39 +0200 Subject: [PATCH 2/4] First E2e test for function deploy --- test/e2e/deploy_function_test.go | 60 +++++++++++++++++++++++ test/e2e/faas_test.go | 82 -------------------------------- test/util.go | 82 ++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 82 deletions(-) create mode 100644 test/e2e/deploy_function_test.go delete mode 100644 test/e2e/faas_test.go diff --git a/test/e2e/deploy_function_test.go b/test/e2e/deploy_function_test.go new file mode 100644 index 00000000..5814f362 --- /dev/null +++ b/test/e2e/deploy_function_test.go @@ -0,0 +1,60 @@ +package e2e + +import ( + goctx "context" + jsfunction "github.com/openshift-cloud-functions/js-function-operator/pkg/apis/faas/v1alpha1" + "github.com/openshift-cloud-functions/js-function-operator/test" + framework "github.com/operator-framework/operator-sdk/pkg/test" + "github.com/stretchr/testify/assert" + "io/ioutil" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + knservingclient "knative.dev/serving/pkg/client/clientset/versioned" + "net/http" + "testing" +) + +const OPERATOR_NAME string = "js-function-operator" + +var ( + functionName = "test-function" + functionSrc = ` + module.exports = context => { + return "ok"; + };` +) + +func TestDeployFunction(t *testing.T) { + ctx, f, namespace := test.E2EBootstrap(t) + + exampleJs := &jsfunction.JSFunction{ + ObjectMeta: metav1.ObjectMeta{ + Name: functionName, + Namespace: namespace, + }, + Spec: jsfunction.JSFunctionSpec{ + Func: functionSrc, + }, + } + + // Create the service + err := f.Client.Create(goctx.TODO(), exampleJs, &framework.CleanupOptions{TestContext: ctx}) + assert.NoError(t, err) + + knClient := knservingclient.NewForConfigOrDie(f.KubeConfig).ServingV1alpha1() + + // Wait for knative service to be ready + knService := test.WaitForKnativeServiceReadyDefault(t, &knClient, functionName, namespace) + serviceURL := knService.Status.Address.URL + + // Try to do a request + res, err := http.Get(serviceURL.String()) + + assert.NoError(t, err) + assert.Equal(t, 200, res.StatusCode) + + body, err := ioutil.ReadAll(res.Body) + + assert.NoError(t, err) + assert.Equal(t, "ok", string(body)) + +} diff --git a/test/e2e/faas_test.go b/test/e2e/faas_test.go deleted file mode 100644 index 53944a29..00000000 --- a/test/e2e/faas_test.go +++ /dev/null @@ -1,82 +0,0 @@ -package e2e - -import ( - goctx "context" - "github.com/openshift-cloud-functions/js-function-operator/pkg/apis" - jsfunction "github.com/openshift-cloud-functions/js-function-operator/pkg/apis/faas/v1alpha1" - framework "github.com/operator-framework/operator-sdk/pkg/test" - "github.com/operator-framework/operator-sdk/pkg/test/e2eutil" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "testing" - "time" -) - -const OPERATOR_NAME string = "js-function-operator" - -var ( - functionName = "test-function" - functionSrc = ` - module.exports = context => { - return "ok"; - };` - retryInterval = time.Second * 5 - timeout = time.Second * 60 - cleanupRetryInterval = time.Second * 1 - cleanupTimeout = time.Second * 5 -) - -func TestJsFaas(t *testing.T) { - // Add CRDs - jsFunctionList := &jsfunction.JSFunctionList{} - err := framework.AddToFrameworkScheme(apis.AddToScheme, jsFunctionList) - if err != nil { - t.Fatalf("failed to add custom resource scheme to framework: %v", err) - } - t.Log("Added CRDs") - - // Setup test framework - ctx := framework.NewTestCtx(t) - defer ctx.Cleanup() - t.Log("Test Framework context ready") - - // Initialize cluster resources - err = ctx.InitializeClusterResources(&framework.CleanupOptions{TestContext: ctx, Timeout: cleanupTimeout, RetryInterval: cleanupRetryInterval}) - if err != nil { - t.Fatalf("failed to initialize cluster resources: %v", err) - } - t.Log("Initialized cluster resources") - - namespace, err := ctx.GetNamespace() - if err != nil { - t.Fatal(err) - } - f := framework.Global - err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, OPERATOR_NAME, 1, retryInterval, timeout) - if err != nil { - t.Fatal(err) - } - t.Log("Operator ready") - - if err = testRunFunction(t, f, ctx, namespace); err != nil { - t.Fatal(err) - } - -} - -func testRunFunction(t *testing.T, f *framework.Framework, ctx *framework.TestCtx, namespace string) error { - exampleJs := &jsfunction.JSFunction{ - ObjectMeta: metav1.ObjectMeta{ - Name: functionName, - Namespace: namespace, - }, - Spec: jsfunction.JSFunctionSpec{ - Func: functionSrc, - }, - } - - err := f.Client.Create(goctx.TODO(), exampleJs, &framework.CleanupOptions{TestContext: ctx}) - if err != nil { - t.Fatal(err) - } - -} diff --git a/test/util.go b/test/util.go index 8b989196..2af14b54 100644 --- a/test/util.go +++ b/test/util.go @@ -1,10 +1,28 @@ package test import ( + "github.com/openshift-cloud-functions/js-function-operator/pkg/apis" + jsfunction "github.com/openshift-cloud-functions/js-function-operator/pkg/apis/faas/v1alpha1" + framework "github.com/operator-framework/operator-sdk/pkg/test" + "github.com/operator-framework/operator-sdk/pkg/test/e2eutil" "github.com/stretchr/testify/assert" "io/ioutil" + metav1errors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/wait" + "knative.dev/serving/pkg/apis/serving/v1alpha1" + servingv1alpha1 "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1" "net/http" "testing" + "time" +) + +const ( + defaultRetryInterval = 1 * time.Second + defaultTimeout = defaultRetryInterval * 40 + cleanupRetryInterval = time.Second * 1 + cleanupTimeout = time.Second * 5 + OPERATOR_NAME = "js-function-operator" ) func AssertGetRequest(t *testing.T, url string, expectedStatusCode int, expectedBody []byte) { @@ -24,3 +42,67 @@ func AssertGetRequest(t *testing.T, url string, expectedStatusCode int, expected assert.Equal(t, expectedBody, b) } + +func WaitForKnativeServiceReadyDefault(t *testing.T, servingClient *servingv1alpha1.ServingV1alpha1Interface, name string, namespace string) *v1alpha1.Service { + return WaitForKnativeServiceReady(t, servingClient, name, namespace, defaultRetryInterval, defaultTimeout) +} + +func WaitForKnativeServiceReady(t *testing.T, servingClient *servingv1alpha1.ServingV1alpha1Interface, name string, namespace string, retryInterval, timeout time.Duration) *v1alpha1.Service { + var service *v1alpha1.Service + + err := wait.Poll(retryInterval, timeout, func() (done bool, err error) { + service, err = (*servingClient).Services(namespace).Get(name, metav1.GetOptions{IncludeUninitialized: true}) + if err != nil { + if metav1errors.IsNotFound(err) { + t.Logf("Waiting for availability of %s service\n", name) + return false, nil + } + return false, err + } + + if service.Status.IsReady() { + return true, nil + } + t.Logf("Waiting for availability of %s service. Actual status: %+v\n", name, service.Status) + return false, nil + }) + + assert.NoError(t, err) + + return service +} + +// This function bootstraps an e2e adding CRDs, initializing the test ctx and deploying the operator +func E2EBootstrap(t *testing.T) (*framework.TestCtx, *framework.Framework, string) { + // Add CRDs + jsFunctionList := &jsfunction.JSFunctionList{} + err := framework.AddToFrameworkScheme(apis.AddToScheme, jsFunctionList) + if err != nil { + t.Fatalf("failed to add custom resource scheme to framework: %v", err) + } + t.Log("Added CRDs") + + // Setup test framework + ctx := framework.NewTestCtx(t) + t.Log("Test Framework context ready") + + // Initialize cluster resources + err = ctx.InitializeClusterResources(&framework.CleanupOptions{TestContext: ctx, Timeout: cleanupTimeout, RetryInterval: cleanupRetryInterval}) + if err != nil { + t.Fatalf("failed to initialize cluster resources: %v", err) + } + t.Log("Initialized cluster resources") + + namespace, err := ctx.GetNamespace() + if err != nil { + t.Fatal(err) + } + f := framework.Global + err = e2eutil.WaitForDeployment(t, f.KubeClient, namespace, OPERATOR_NAME, 1, defaultRetryInterval, defaultTimeout) + if err != nil { + t.Fatal(err) + } + t.Log("Operator ready") + + return ctx, f, namespace +} From ccd3a99b9696724cafb8d7ba39aa35d3171312b2 Mon Sep 17 00:00:00 2001 From: slinkydeveloper Date: Mon, 2 Sep 2019 16:59:34 +0200 Subject: [PATCH 3/4] Modified run_e2e.sh --- Gopkg.lock | 10 ++++++++++ test/e2e/deploy_function_test.go | 4 ++-- test/run_e2e.sh | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 test/run_e2e.sh diff --git a/Gopkg.lock b/Gopkg.lock index d169505a..e83896ee 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1374,12 +1374,19 @@ name = "knative.dev/serving" packages = [ "pkg/apis/autoscaling", + "pkg/apis/autoscaling/v1alpha1", "pkg/apis/config", "pkg/apis/networking", "pkg/apis/networking/v1alpha1", "pkg/apis/serving", "pkg/apis/serving/v1alpha1", "pkg/apis/serving/v1beta1", + "pkg/client/clientset/versioned", + "pkg/client/clientset/versioned/scheme", + "pkg/client/clientset/versioned/typed/autoscaling/v1alpha1", + "pkg/client/clientset/versioned/typed/networking/v1alpha1", + "pkg/client/clientset/versioned/typed/serving/v1alpha1", + "pkg/client/clientset/versioned/typed/serving/v1beta1", "pkg/gc", "pkg/network", "pkg/reconciler/route/config", @@ -1470,6 +1477,7 @@ "k8s.io/apimachinery/pkg/runtime", "k8s.io/apimachinery/pkg/runtime/schema", "k8s.io/apimachinery/pkg/types", + "k8s.io/apimachinery/pkg/util/wait", "k8s.io/client-go/plugin/pkg/client/auth", "k8s.io/code-generator/cmd/client-gen", "k8s.io/code-generator/cmd/conversion-gen", @@ -1482,6 +1490,8 @@ "knative.dev/eventing/pkg/apis/eventing/v1alpha1", "knative.dev/serving/pkg/apis/serving/v1alpha1", "knative.dev/serving/pkg/apis/serving/v1beta1", + "knative.dev/serving/pkg/client/clientset/versioned", + "knative.dev/serving/pkg/client/clientset/versioned/typed/serving/v1alpha1", "sigs.k8s.io/controller-runtime/pkg/client", "sigs.k8s.io/controller-runtime/pkg/client/config", "sigs.k8s.io/controller-runtime/pkg/controller", diff --git a/test/e2e/deploy_function_test.go b/test/e2e/deploy_function_test.go index 5814f362..75e82e08 100644 --- a/test/e2e/deploy_function_test.go +++ b/test/e2e/deploy_function_test.go @@ -13,8 +13,6 @@ import ( "testing" ) -const OPERATOR_NAME string = "js-function-operator" - var ( functionName = "test-function" functionSrc = ` @@ -26,6 +24,8 @@ var ( func TestDeployFunction(t *testing.T) { ctx, f, namespace := test.E2EBootstrap(t) + t.Logf("Deploying function in namespace %v", namespace) + exampleJs := &jsfunction.JSFunction{ ObjectMeta: metav1.ObjectMeta{ Name: functionName, diff --git a/test/run_e2e.sh b/test/run_e2e.sh new file mode 100644 index 00000000..eaedbba5 --- /dev/null +++ b/test/run_e2e.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +kubectl create namespace operator-test +kubectl create -f deploy/crds/faas_v1alpha1_jsfunction_crd.yaml +kubectl create -f deploy/service_account.yaml --namespace operator-test +kubectl create -f deploy/role.yaml --namespace operator-test +kubectl create -f deploy/role_binding.yaml --namespace operator-test +kubectl create -f deploy/operator.yaml --namespace operator-test + +oc adm policy add-role-to-user edit -z js-function-operator +oc adm policy add-scc-to-user privileged -z js-function-operator + +operator-sdk test local ./test/e2e --namespace operator-test --no-setup --verbose + +kubectl delete namespace operator-test \ No newline at end of file From df2bf00073c53a50ae94a42fb5dac07a24bc24db Mon Sep 17 00:00:00 2001 From: slinkydeveloper Date: Wed, 4 Sep 2019 14:49:16 +0200 Subject: [PATCH 4/4] Applied suggestions --- test/e2e/deploy_function_test.go | 13 +------------ test/run_e2e.sh | 2 +- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/test/e2e/deploy_function_test.go b/test/e2e/deploy_function_test.go index 75e82e08..75349fe0 100644 --- a/test/e2e/deploy_function_test.go +++ b/test/e2e/deploy_function_test.go @@ -6,10 +6,8 @@ import ( "github.com/openshift-cloud-functions/js-function-operator/test" framework "github.com/operator-framework/operator-sdk/pkg/test" "github.com/stretchr/testify/assert" - "io/ioutil" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" knservingclient "knative.dev/serving/pkg/client/clientset/versioned" - "net/http" "testing" ) @@ -46,15 +44,6 @@ func TestDeployFunction(t *testing.T) { knService := test.WaitForKnativeServiceReadyDefault(t, &knClient, functionName, namespace) serviceURL := knService.Status.Address.URL - // Try to do a request - res, err := http.Get(serviceURL.String()) - - assert.NoError(t, err) - assert.Equal(t, 200, res.StatusCode) - - body, err := ioutil.ReadAll(res.Body) - - assert.NoError(t, err) - assert.Equal(t, "ok", string(body)) + test.AssertGetRequest(t, serviceURL.String(), 200, []byte("ok")) } diff --git a/test/run_e2e.sh b/test/run_e2e.sh index eaedbba5..e1c353c8 100644 --- a/test/run_e2e.sh +++ b/test/run_e2e.sh @@ -12,4 +12,4 @@ oc adm policy add-scc-to-user privileged -z js-function-operator operator-sdk test local ./test/e2e --namespace operator-test --no-setup --verbose -kubectl delete namespace operator-test \ No newline at end of file +kubectl delete namespace operator-test