Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some linter errors in integration tests #2608

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions pkg/docker/runner_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,6 +128,9 @@ func TestRunDigested(t *testing.T) {

// prebuild default image
f, err = client.Build(ctx, f)
if err != nil {
matejvasek marked this conversation as resolved.
Show resolved Hide resolved
t.Fatal(err)
}

// simulate passing image from --image flag since client.Run just sets
// a timeout and simply calls runner.Run.
Expand Down
24 changes: 18 additions & 6 deletions pkg/functions/client_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 12 additions & 9 deletions pkg/k8s/dialer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/k8s/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/persistent_volumes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/knative/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pipelines/tekton/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/pipelines/tekton/pipelines_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
Loading