diff --git a/pkg/docker/runner_int_test.go b/pkg/docker/runner_int_test.go index 6cc15069e..2c9ac07b4 100644 --- a/pkg/docker/runner_int_test.go +++ b/pkg/docker/runner_int_test.go @@ -50,6 +50,9 @@ func TestRun(t *testing.T) { } f, err = client.Build(ctx, f) + if err != nil { + t.Fatal(err) + } // Run the function using a docker runner var out, errOut bytes.Buffer @@ -115,7 +118,7 @@ func TestRunDigested(t *testing.T) { image := testImageWithDigest prePullTestImages(t, image) - f := fn.Function{Runtime: "go", Root: root} + f := fn.Function{Runtime: "go", Root: root, Registry: "docker.io/jdoe"} client := fn.New() f, err := client.Init(f) @@ -125,6 +128,9 @@ func TestRunDigested(t *testing.T) { // prebuild default image f, err = client.Build(ctx, f) + if err != nil { + t.Fatal(err) + } // simulate passing image from --image flag since client.Run just sets // a timeout and simply calls runner.Run. diff --git a/pkg/functions/client_int_test.go b/pkg/functions/client_int_test.go index 47ade0755..464303657 100644 --- a/pkg/functions/client_int_test.go +++ b/pkg/functions/client_int_test.go @@ -206,6 +206,9 @@ func TestUpdateWithAnnotationsAndLabels(t *testing.T) { verbose := false servingClient, err := knative.NewServingClient(DefaultNamespace) + if err != nil { + t.Fatal(err) + } // Deploy a function without any annotations or labels client := newClient(verbose) @@ -300,7 +303,7 @@ func TestRemove(t *testing.T) { client := newClient(verbose) f := fn.Function{Name: "remove", Namespace: DefaultNamespace, Root: ".", Runtime: "go"} var err error - if _, f, err = client.New(context.Background(), f); err != nil { + if _, _, err = client.New(context.Background(), f); err != nil { t.Fatal(err) } @@ -397,7 +400,10 @@ func Handle(ctx context.Context, res http.ResponseWriter, req *http.Request) { res.Write([]byte("TestInvoke_ClientToService OK")) } ` - os.WriteFile(filepath.Join(root, "handle.go"), []byte(source), os.ModePerm) + err = os.WriteFile(filepath.Join(root, "handle.go"), []byte(source), os.ModePerm) + if err != nil { + t.Fatal(err) + } if route, f, err = client.Apply(ctx, f); err != nil { t.Fatal(err) @@ -466,8 +472,11 @@ func Handle(ctx context.Context, res http.ResponseWriter, req *http.Request) { res.Write([]byte("TestInvoke_ServiceToService OK")) } ` - os.WriteFile(filepath.Join(root, "handle.go"), []byte(source), os.ModePerm) - if _, f, err = client.Apply(ctx, f); err != nil { + err = os.WriteFile(filepath.Join(root, "handle.go"), []byte(source), os.ModePerm) + if err != nil { + t.Fatal(err) + } + if _, _, err = client.Apply(ctx, f); err != nil { t.Fatal(err) } defer del(t, client, "a", DefaultNamespace) @@ -522,8 +531,11 @@ func Handle(ctx context.Context, w http.ResponseWriter, req *http.Request) { return } ` - os.WriteFile(filepath.Join(root, "handle.go"), []byte(source), os.ModePerm) - if route, f, err = client.Apply(ctx, f); err != nil { + err = os.WriteFile(filepath.Join(root, "handle.go"), []byte(source), os.ModePerm) + if err != nil { + t.Fatal(err) + } + if route, _, err = client.Apply(ctx, f); err != nil { t.Fatal(err) } defer del(t, client, "b", DefaultNamespace) diff --git a/pkg/k8s/dialer_test.go b/pkg/k8s/dialer_test.go index fa7ae9203..fa8538bd0 100644 --- a/pkg/k8s/dialer_test.go +++ b/pkg/k8s/dialer_test.go @@ -11,10 +11,11 @@ import ( "net/http" "regexp" "strings" - "sync" "testing" "time" + "golang.org/x/sync/errgroup" + appsV1 "k8s.io/api/apps/v1" coreV1 "k8s.io/api/core/v1" metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -163,20 +164,22 @@ func TestDialInClusterService(t *testing.T) { t.Errorf("unexpected status code: %d", resp.StatusCode) } - var wg sync.WaitGroup + var eg errgroup.Group for i := 0; i < 10; i++ { - wg.Add(1) - go func() { - defer wg.Done() + eg.Go(func() error { resp, err := client.Get(svcInClusterURL) if err != nil { - t.Fatal(err) + return err } defer resp.Body.Close() - io.Copy(io.Discard, resp.Body) - }() + _, err = io.Copy(io.Discard, resp.Body) + return err + }) + } + err = eg.Wait() + if err != nil { + t.Fatal(err) } - wg.Wait() } func TestDialUnreachable(t *testing.T) { diff --git a/pkg/k8s/logs_test.go b/pkg/k8s/logs_test.go index 4dccc4c90..57191bcc1 100644 --- a/pkg/k8s/logs_test.go +++ b/pkg/k8s/logs_test.go @@ -35,7 +35,7 @@ func TestGetPodLogs(t *testing.T) { t.Fatal(err) } t.Cleanup(func() { - cliSet.CoreV1().Namespaces().Delete(ctx, testingNS, metav1.DeleteOptions{}) + _ = cliSet.CoreV1().Namespaces().Delete(ctx, testingNS, metav1.DeleteOptions{}) }) t.Log("created namespace: ", testingNS) @@ -61,7 +61,7 @@ func TestGetPodLogs(t *testing.T) { }, } - pod, err = cliSet.CoreV1().Pods(testingNS).Create(ctx, pod, metav1.CreateOptions{}) + _, err = cliSet.CoreV1().Pods(testingNS).Create(ctx, pod, metav1.CreateOptions{}) if err != nil { t.Fatal(err) } diff --git a/pkg/k8s/persistent_volumes_test.go b/pkg/k8s/persistent_volumes_test.go index 57805bc0b..9b329abec 100644 --- a/pkg/k8s/persistent_volumes_test.go +++ b/pkg/k8s/persistent_volumes_test.go @@ -98,7 +98,7 @@ func TestUploadToVolume(t *testing.T) { }, } - pod, err = cliSet.CoreV1().Pods(testingNS).Create(ctx, pod, metav1.CreateOptions{}) + _, err = cliSet.CoreV1().Pods(testingNS).Create(ctx, pod, metav1.CreateOptions{}) if err != nil { t.Fatal(err) } diff --git a/pkg/knative/integration_test.go b/pkg/knative/integration_test.go index c05de554c..5edf89d03 100644 --- a/pkg/knative/integration_test.go +++ b/pkg/knative/integration_test.go @@ -63,7 +63,7 @@ func TestIntegration(t *testing.T) { Type: corev1.SecretTypeOpaque, } - sc, err = cliSet.CoreV1().Secrets(namespace).Create(ctx, sc, metav1.CreateOptions{}) + _, err = cliSet.CoreV1().Secrets(namespace).Create(ctx, sc, metav1.CreateOptions{}) if err != nil { t.Fatal(err) } @@ -75,7 +75,7 @@ func TestIntegration(t *testing.T) { }, Data: map[string]string{"FUNC_TEST_CM_A": "1"}, } - cm, err = cliSet.CoreV1().ConfigMaps(namespace).Create(ctx, cm, metav1.CreateOptions{}) + _, err = cliSet.CoreV1().ConfigMaps(namespace).Create(ctx, cm, metav1.CreateOptions{}) if err != nil { t.Fatal(err) } @@ -187,7 +187,7 @@ func TestIntegration(t *testing.T) { if !strings.Contains(outStr, "FUNC_TEST_CM_A=1") { t.Error("environment variable from config-map was not propagated") } - if !strings.Contains(outStr, "/etc/sc/FUNC_TEST_SC_A") || !strings.Contains(outStr, "/etc/sc/FUNC_TEST_SC_A") { + if !strings.Contains(outStr, "/etc/sc/FUNC_TEST_SC_A") { t.Error("secret was not mounted") } if !strings.Contains(outStr, "/etc/cm/FUNC_TEST_CM_A") { @@ -250,7 +250,7 @@ func TestIntegration(t *testing.T) { {Value: ptr("{{ secret: " + secret + " }}")}, {Name: ptr("FUNC_TEST_CM_A_ALIASED"), Value: ptr("{{configMap:" + configMap + ":FUNC_TEST_CM_A}}")}, } - depRes, err = deployer.Deploy(ctx, function) + _, err = deployer.Deploy(ctx, function) if err != nil { t.Fatal(err) } diff --git a/pkg/pipelines/tekton/gitlab_test.go b/pkg/pipelines/tekton/gitlab_test.go index 96c82d497..f53a1dc59 100644 --- a/pkg/pipelines/tekton/gitlab_test.go +++ b/pkg/pipelines/tekton/gitlab_test.go @@ -594,7 +594,7 @@ func usingNamespace(t *testing.T) string { }, } createOpts := metav1.CreateOptions{} - ns, err = k8sClient.CoreV1().Namespaces().Create(context.Background(), ns, createOpts) + _, err = k8sClient.CoreV1().Namespaces().Create(context.Background(), ns, createOpts) if err != nil { t.Fatal(err) } diff --git a/pkg/pipelines/tekton/pipelines_integration_test.go b/pkg/pipelines/tekton/pipelines_integration_test.go index 22e6cdf65..ae05aea27 100644 --- a/pkg/pipelines/tekton/pipelines_integration_test.go +++ b/pkg/pipelines/tekton/pipelines_integration_test.go @@ -79,7 +79,7 @@ func assertFunctionEchoes(url string) (err error) { defer res.Body.Close() if !strings.Contains(string(body), token) { err = fmt.Errorf("response did not contain token. url: %v", url) - httputil.DumpResponse(res, true) + _, _ = httputil.DumpResponse(res, true) } return } @@ -135,7 +135,9 @@ func TestRemote_Default(t *testing.T) { if url, f, err = client.RunPipeline(ctx, f); err != nil { t.Fatal(err) } - defer client.Remove(ctx, "", "", f, true) + defer func() { + _ = client.Remove(ctx, "", "", f, true) + }() if err := assertFunctionEchoes(url); err != nil { t.Fatal(err)