From 9cacef302bca869da1700b72bede1afad0e9526d Mon Sep 17 00:00:00 2001 From: Anton Gilgur <4970083+agilgur5@users.noreply.github.com> Date: Tue, 14 May 2024 19:19:02 -0400 Subject: [PATCH] refactor(test): use `t.Setenv` (#13036) Signed-off-by: Anton Gilgur --- cmd/argo/commands/client/conn_test.go | 7 ++--- server/auth/gatekeeper_test.go | 13 +++------ server/cache/resource_cache_test.go | 4 +-- .../archived_workflow_server_test.go | 4 +-- util/env/env_test.go | 27 ++++++++----------- util/errors/errors_test.go | 8 +++--- util/file/fileutil_test.go | 6 ++--- util/kubeconfig/kubeconfig_test.go | 2 +- util/util_test.go | 5 ++-- workflow/artifacts/s3/s3_test.go | 12 +++------ workflow/controller/operator_test.go | 18 ++++--------- workflow/controller/pod/significant_test.go | 4 +-- .../events/event_recorder_manager_test.go | 7 ++--- workflow/executor/resource_test.go | 4 +-- 14 files changed, 40 insertions(+), 81 deletions(-) diff --git a/cmd/argo/commands/client/conn_test.go b/cmd/argo/commands/client/conn_test.go index f98a4e9f6c2b..b3d992d3e1f2 100644 --- a/cmd/argo/commands/client/conn_test.go +++ b/cmd/argo/commands/client/conn_test.go @@ -2,7 +2,6 @@ package client import ( "context" - "os" "testing" "github.com/sirupsen/logrus" @@ -10,14 +9,12 @@ import ( ) func TestGetAuthString(t *testing.T) { - _ = os.Setenv("ARGO_TOKEN", "my-token") - defer func() { _ = os.Unsetenv("ARGO_TOKEN") }() + t.Setenv("ARGO_TOKEN", "my-token") assert.Equal(t, "my-token", GetAuthString()) } func TestNamespace(t *testing.T) { - _ = os.Setenv("ARGO_NAMESPACE", "my-ns") - defer func() { _ = os.Unsetenv("ARGO_NAMESPACE") }() + t.Setenv("ARGO_NAMESPACE", "my-ns") assert.Equal(t, "my-ns", Namespace()) } diff --git a/server/auth/gatekeeper_test.go b/server/auth/gatekeeper_test.go index 27d9f47db76a..755727ad7b1a 100644 --- a/server/auth/gatekeeper_test.go +++ b/server/auth/gatekeeper_test.go @@ -2,7 +2,6 @@ package auth import ( "context" - "os" "testing" "github.com/go-jose/go-jose/v3/jwt" @@ -26,8 +25,7 @@ import ( func TestServer_GetWFClient(t *testing.T) { // prevent using local KUBECONFIG - which will fail on CI - _ = os.Setenv("KUBECONFIG", "/dev/null") - defer func() { _ = os.Unsetenv("KUBECONFIG") }() + t.Setenv("KUBECONFIG", "/dev/null") wfClient := fakewfclientset.NewSimpleClientset() kubeClient := kubefake.NewSimpleClientset( &corev1.ServiceAccount{ @@ -189,7 +187,7 @@ func TestServer_GetWFClient(t *testing.T) { } }) t.Run("SSO+RBAC, Namespace delegation ON, precedence=2, Delegated", func(t *testing.T) { - os.Setenv("SSO_DELEGATE_RBAC_TO_NAMESPACE", "true") + t.Setenv("SSO_DELEGATE_RBAC_TO_NAMESPACE", "true") ssoIf := &ssomocks.Interface{} ssoIf.On("Authorize", mock.Anything, mock.Anything).Return(&types.Claims{Groups: []string{"my-group", "other-group"}}, nil) ssoIf.On("IsRBACEnabled").Return(true) @@ -208,7 +206,6 @@ func TestServer_GetWFClient(t *testing.T) { assert.Equal(t, "user1-sa", hook.LastEntry().Data["serviceAccount"]) } } - os.Unsetenv("SSO_DELEGATE_RBAC_TO_NAMESPACE") }) t.Run("SSO+RBAC, Namespace delegation OFF, precedence=2, Not Delegated", func(t *testing.T) { ssoIf := &ssomocks.Interface{} @@ -231,7 +228,7 @@ func TestServer_GetWFClient(t *testing.T) { } }) t.Run("SSO+RBAC, Namespace delegation ON, precedence=0, Not delegated", func(t *testing.T) { - os.Setenv("SSO_DELEGATE_RBAC_TO_NAMESPACE", "true") + t.Setenv("SSO_DELEGATE_RBAC_TO_NAMESPACE", "true") ssoIf := &ssomocks.Interface{} ssoIf.On("Authorize", mock.Anything, mock.Anything).Return(&types.Claims{Groups: []string{"my-group", "other-group"}}, nil) ssoIf.On("IsRBACEnabled").Return(true) @@ -250,10 +247,9 @@ func TestServer_GetWFClient(t *testing.T) { assert.Equal(t, "my-sa", hook.LastEntry().Data["serviceAccount"]) } } - os.Unsetenv("SSO_DELEGATE_RBAC_TO_NAMESPACE") }) t.Run("SSO+RBAC, Namespace delegation ON, precedence=1, Not delegated", func(t *testing.T) { - os.Setenv("SSO_DELEGATE_RBAC_TO_NAMESPACE", "true") + t.Setenv("SSO_DELEGATE_RBAC_TO_NAMESPACE", "true") ssoIf := &ssomocks.Interface{} ssoIf.On("Authorize", mock.Anything, mock.Anything).Return(&types.Claims{Groups: []string{"my-group", "other-group"}}, nil) ssoIf.On("IsRBACEnabled").Return(true) @@ -272,7 +268,6 @@ func TestServer_GetWFClient(t *testing.T) { assert.Equal(t, "my-sa", hook.LastEntry().Data["serviceAccount"]) } } - os.Unsetenv("SSO_DELEGATE_RBAC_TO_NAMESPACE") }) t.Run("SSO+RBAC,precedence=0", func(t *testing.T) { ssoIf := &ssomocks.Interface{} diff --git a/server/cache/resource_cache_test.go b/server/cache/resource_cache_test.go index ae93ce51c9a4..9eea9065d0e5 100644 --- a/server/cache/resource_cache_test.go +++ b/server/cache/resource_cache_test.go @@ -2,7 +2,6 @@ package cache import ( "context" - "os" "testing" "github.com/stretchr/testify/assert" @@ -24,8 +23,7 @@ func checkServiceAccountExists(saList []*v1.ServiceAccount, name string) bool { } func TestServer_K8sUtilsCache(t *testing.T) { - _ = os.Setenv("KUBECONFIG", "/dev/null") - defer func() { _ = os.Unsetenv("KUBECONFIG") }() + t.Setenv("KUBECONFIG", "/dev/null") saLabels := make(map[string]string) saLabels["hello"] = "world" diff --git a/server/workflowarchive/archived_workflow_server_test.go b/server/workflowarchive/archived_workflow_server_test.go index 7f26bbbb20eb..b1b910f763ef 100644 --- a/server/workflowarchive/archived_workflow_server_test.go +++ b/server/workflowarchive/archived_workflow_server_test.go @@ -2,7 +2,6 @@ package workflowarchive import ( "context" - "os" "testing" "time" @@ -241,13 +240,12 @@ func Test_archivedWorkflowServer(t *testing.T) { assert.Len(t, resp.Items, 2) assert.False(t, matchLabelKeyPattern("my-key")) - _ = os.Setenv(disableValueListRetrievalKeyPattern, "my-key") + t.Setenv(disableValueListRetrievalKeyPattern, "my-key") assert.True(t, matchLabelKeyPattern("my-key")) assert.False(t, matchLabelKeyPattern("wrong key")) resp, err = w.ListArchivedWorkflowLabelValues(ctx, &workflowarchivepkg.ListArchivedWorkflowLabelValuesRequest{ListOptions: &metav1.ListOptions{LabelSelector: "my-key"}}) assert.NoError(t, err) assert.Len(t, resp.Items, 0) - _ = os.Unsetenv(disableValueListRetrievalKeyPattern) }) t.Run("RetryArchivedWorkflow", func(t *testing.T) { _, err := w.RetryArchivedWorkflow(ctx, &workflowarchivepkg.RetryArchivedWorkflowRequest{Uid: "failed-uid"}) diff --git a/util/env/env_test.go b/util/env/env_test.go index ec52cbbfd552..d8153e4f0ee6 100644 --- a/util/env/env_test.go +++ b/util/env/env_test.go @@ -1,7 +1,6 @@ package env import ( - "os" "testing" "time" @@ -9,43 +8,39 @@ import ( ) func TestLookupEnvDurationOr(t *testing.T) { - defer func() { _ = os.Unsetenv("FOO") }() assert.Equal(t, time.Second, LookupEnvDurationOr("", time.Second), "default value") - _ = os.Setenv("FOO", "bar") + t.Setenv("FOO", "bar") assert.Panics(t, func() { LookupEnvDurationOr("FOO", time.Second) }, "bad value") - _ = os.Setenv("FOO", "1h") + t.Setenv("FOO", "1h") assert.Equal(t, time.Hour, LookupEnvDurationOr("FOO", time.Second), "env var value") - _ = os.Setenv("FOO", "") + t.Setenv("FOO", "") assert.Equal(t, time.Second, LookupEnvDurationOr("FOO", time.Second), "empty var value; default value") } func TestLookupEnvIntOr(t *testing.T) { - defer func() { _ = os.Unsetenv("FOO") }() assert.Equal(t, 1, LookupEnvIntOr("", 1), "default value") - _ = os.Setenv("FOO", "not-int") + t.Setenv("FOO", "not-int") assert.Panics(t, func() { LookupEnvIntOr("FOO", 1) }, "bad value") - _ = os.Setenv("FOO", "2") + t.Setenv("FOO", "2") assert.Equal(t, 2, LookupEnvIntOr("FOO", 1), "env var value") - _ = os.Setenv("FOO", "") + t.Setenv("FOO", "") assert.Equal(t, 1, LookupEnvIntOr("FOO", 1), "empty var value; default value") } func TestLookupEnvFloatOr(t *testing.T) { - defer func() { _ = os.Unsetenv("FOO") }() assert.Equal(t, 1., LookupEnvFloatOr("", 1.), "default value") - _ = os.Setenv("FOO", "not-float") + t.Setenv("FOO", "not-float") assert.Panics(t, func() { LookupEnvFloatOr("FOO", 1.) }, "bad value") - _ = os.Setenv("FOO", "2.0") + t.Setenv("FOO", "2.0") assert.Equal(t, 2., LookupEnvFloatOr("FOO", 1.), "env var value") - _ = os.Setenv("FOO", "") + t.Setenv("FOO", "") assert.Equal(t, 1., LookupEnvFloatOr("FOO", 1.), "empty var value; default value") } func TestLookupEnvStringOr(t *testing.T) { - defer func() { _ = os.Unsetenv("FOO") }() assert.Equal(t, "a", LookupEnvStringOr("", "a"), "default value") - _ = os.Setenv("FOO", "b") + t.Setenv("FOO", "b") assert.Equal(t, "b", LookupEnvStringOr("FOO", "a"), "env var value") - _ = os.Setenv("FOO", "") + t.Setenv("FOO", "") assert.Equal(t, "a", LookupEnvStringOr("FOO", "a"), "empty var value; default value") } diff --git a/util/errors/errors_test.go b/util/errors/errors_test.go index 8374bc0941f9..8090072c1ae1 100644 --- a/util/errors/errors_test.go +++ b/util/errors/errors_test.go @@ -90,18 +90,16 @@ func TestIsTransientErr(t *testing.T) { assert.True(t, IsTransientErr(connectionResetErr)) }) t.Run("TransientErrorPattern", func(t *testing.T) { - _ = os.Setenv(transientEnvVarKey, "this error is transient") + t.Setenv(transientEnvVarKey, "this error is transient") assert.True(t, IsTransientErr(transientErr)) assert.True(t, IsTransientErr(&transientExitErr)) - _ = os.Setenv(transientEnvVarKey, "this error is not transient") + t.Setenv(transientEnvVarKey, "this error is not transient") assert.False(t, IsTransientErr(transientErr)) assert.False(t, IsTransientErr(&transientExitErr)) - _ = os.Setenv(transientEnvVarKey, "") + t.Setenv(transientEnvVarKey, "") assert.False(t, IsTransientErr(transientErr)) - - _ = os.Unsetenv(transientEnvVarKey) }) t.Run("ExplicitTransientErr", func(t *testing.T) { assert.True(t, IsTransientErr(NewErrTransient(""))) diff --git a/util/file/fileutil_test.go b/util/file/fileutil_test.go index 3f978b97a276..9bae536f0b55 100644 --- a/util/file/fileutil_test.go +++ b/util/file/fileutil_test.go @@ -16,7 +16,7 @@ import ( // TestCompressContentString ensures compressing then decompressing a content string works as expected func TestCompressContentString(t *testing.T) { for _, gzipImpl := range []string{file.GZIP, file.PGZIP} { - _ = os.Setenv(file.GZipImplEnvVarKey, gzipImpl) + t.Setenv(file.GZipImplEnvVarKey, gzipImpl) content := "{\"pod-limits-rrdm8-591645159\":{\"id\":\"pod-limits-rrdm8-591645159\",\"name\":\"pod-limits-rrdm8[0]." + "run-pod(0:0)\",\"displayName\":\"run-pod(0:0)\",\"type\":\"Pod\",\"templateName\":\"run-pod\",\"phase\":" + "\"Succeeded\",\"boundaryID\":\"pod-limits-rrdm8\",\"startedAt\":\"2019-03-07T19:14:50Z\",\"finishedAt\":" + @@ -28,13 +28,12 @@ func TestCompressContentString(t *testing.T) { assert.Equal(t, content, resultString) } - _ = os.Unsetenv(file.GZipImplEnvVarKey) } // TestGetGzipReader checks whether we can obtain the Gzip reader based on environment variable. func TestGetGzipReader(t *testing.T) { for _, gzipImpl := range []string{file.GZIP, file.PGZIP} { - _ = os.Setenv(file.GZipImplEnvVarKey, gzipImpl) + t.Setenv(file.GZipImplEnvVarKey, gzipImpl) rawContent := "this is the content" content := file.CompressEncodeString(rawContent) buf, err := base64.StdEncoding.DecodeString(content) @@ -45,7 +44,6 @@ func TestGetGzipReader(t *testing.T) { res, err := io.ReadAll(reader) assert.NoError(t, err) assert.Equal(t, rawContent, string(res)) - _ = os.Unsetenv(file.GZipImplEnvVarKey) } } diff --git a/util/kubeconfig/kubeconfig_test.go b/util/kubeconfig/kubeconfig_test.go index e14f8d3e9570..45bf02cbe9e2 100644 --- a/util/kubeconfig/kubeconfig_test.go +++ b/util/kubeconfig/kubeconfig_test.go @@ -50,7 +50,7 @@ func Test_BasicAuthString(t *testing.T) { assert.NoError(t, err) err = file.Close() assert.NoError(t, err) - os.Setenv("KUBECONFIG", file.Name()) + t.Setenv("KUBECONFIG", file.Name()) config, err := GetRestConfig(authString) if assert.NoError(t, err) { assert.Equal(t, "admin", config.Username) diff --git a/util/util_test.go b/util/util_test.go index fc281f0256fc..c0cd3e120b10 100644 --- a/util/util_test.go +++ b/util/util_test.go @@ -1,7 +1,6 @@ package util import ( - "os" "testing" "github.com/stretchr/testify/assert" @@ -74,11 +73,11 @@ func TestGetDeletePropagation(t *testing.T) { assert.Equal(t, metav1.DeletePropagationBackground, *GetDeletePropagation()) }) t.Run("GetEnvPolicy", func(t *testing.T) { - os.Setenv("WF_DEL_PROPAGATION_POLICY", "Foreground") + t.Setenv("WF_DEL_PROPAGATION_POLICY", "Foreground") assert.Equal(t, metav1.DeletePropagationForeground, *GetDeletePropagation()) }) t.Run("GetEnvPolicyWithEmpty", func(t *testing.T) { - os.Setenv("WF_DEL_PROPAGATION_POLICY", "") + t.Setenv("WF_DEL_PROPAGATION_POLICY", "") assert.Equal(t, metav1.DeletePropagationBackground, *GetDeletePropagation()) }) } diff --git a/workflow/artifacts/s3/s3_test.go b/workflow/artifacts/s3/s3_test.go index f3ad6cf94b8f..4a6d9a30d905 100644 --- a/workflow/artifacts/s3/s3_test.go +++ b/workflow/artifacts/s3/s3_test.go @@ -215,7 +215,7 @@ func TestOpenStreamS3Artifact(t *testing.T) { }, } - _ = os.Setenv(transientEnvVarKey, "this error is transient") + t.Setenv(transientEnvVarKey, "this error is transient") for name, tc := range tests { t.Run(name, func(t *testing.T) { stream, err := streamS3Artifact(tc.s3client, &wfv1.Artifact{ @@ -237,7 +237,6 @@ func TestOpenStreamS3Artifact(t *testing.T) { } }) } - _ = os.Unsetenv(transientEnvVarKey) } // Delete deletes an S3 artifact by artifact key @@ -380,7 +379,7 @@ func TestLoadS3Artifact(t *testing.T) { }, } - _ = os.Setenv(transientEnvVarKey, "this error is transient") + t.Setenv(transientEnvVarKey, "this error is transient") for name, tc := range tests { t.Run(name, func(t *testing.T) { success, err := loadS3Artifact(tc.s3client, &wfv1.Artifact{ @@ -401,7 +400,6 @@ func TestLoadS3Artifact(t *testing.T) { } }) } - _ = os.Unsetenv(transientEnvVarKey) } func TestSaveS3Artifact(t *testing.T) { @@ -509,7 +507,7 @@ func TestSaveS3Artifact(t *testing.T) { } for name, tc := range tests { - _ = os.Setenv(transientEnvVarKey, "this error is transient") + t.Setenv(transientEnvVarKey, "this error is transient") t.Run(name, func(t *testing.T) { success, err := saveS3Artifact( tc.s3client, @@ -535,7 +533,6 @@ func TestSaveS3Artifact(t *testing.T) { assert.Equal(t, tc.errMsg, "") } }) - _ = os.Unsetenv(transientEnvVarKey) } } @@ -590,7 +587,7 @@ func TestListObjects(t *testing.T) { }, } - _ = os.Setenv(transientEnvVarKey, "this error is transient") + t.Setenv(transientEnvVarKey, "this error is transient") for name, tc := range tests { t.Run(name, func(t *testing.T) { _, files, err := listObjects(tc.s3client, @@ -617,5 +614,4 @@ func TestListObjects(t *testing.T) { } }) } - _ = os.Unsetenv(transientEnvVarKey) } diff --git a/workflow/controller/operator_test.go b/workflow/controller/operator_test.go index 91992b56d4f3..9da3e37c31e1 100644 --- a/workflow/controller/operator_test.go +++ b/workflow/controller/operator_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "errors" "fmt" - "os" "regexp" "strconv" "strings" @@ -728,13 +727,12 @@ func TestProcessNodeRetriesOnTransientErrors(t *testing.T) { transientEnvVarKey := "TRANSIENT_ERROR_PATTERN" transientErrMsg := "This error is transient" woc.markNodePhase(lastChild.Name, wfv1.NodeError, transientErrMsg) - _ = os.Setenv(transientEnvVarKey, transientErrMsg) + t.Setenv(transientEnvVarKey, transientErrMsg) _, _, err = woc.processNodeRetries(n, retries, &executeTemplateOpts{}) assert.NoError(t, err) n, err = woc.wf.GetNodeByName(nodeName) assert.NoError(t, err) assert.Equal(t, n.Phase, wfv1.NodeRunning) - _ = os.Unsetenv(transientEnvVarKey) // Add a third node that has errored. childNode := fmt.Sprintf("%s(%d)", nodeName, 3) @@ -3366,7 +3364,7 @@ func TestResolvePodNameInRetries(t *testing.T) { {"v2", "output-value-placeholders-wf-tell-pod-name-3033990984"}, } for _, tt := range tests { - _ = os.Setenv("POD_NAMES", tt.podNameVersion) + t.Setenv("POD_NAMES", tt.podNameVersion) ctx := context.Background() wf := wfv1.MustUnmarshalWorkflow(podNameInRetries) woc := newWoc(*wf) @@ -9374,10 +9372,6 @@ spec: } func TestSetWFPodNamesAnnotation(t *testing.T) { - defer func() { - _ = os.Unsetenv("POD_NAMES") - }() - tests := []struct { podNameVersion string }{ @@ -9386,7 +9380,7 @@ func TestSetWFPodNamesAnnotation(t *testing.T) { } for _, tt := range tests { - _ = os.Setenv("POD_NAMES", tt.podNameVersion) + t.Setenv("POD_NAMES", tt.podNameVersion) wf := wfv1.MustUnmarshalWorkflow(exitHandlerWithRetryNodeParam) cancel, controller := newController(wf) @@ -10383,7 +10377,7 @@ func TestMaxDepthEnvVariable(t *testing.T) { controller.maxStackDepth = 2 ctx := context.Background() woc := newWorkflowOperationCtx(wf, controller) - _ = os.Setenv("DISABLE_MAX_RECURSION", "true") + t.Setenv("DISABLE_MAX_RECURSION", "true") woc.operate(ctx) @@ -10400,8 +10394,6 @@ func TestMaxDepthEnvVariable(t *testing.T) { makePodsPhase(ctx, woc, apiv1.PodSucceeded) woc.operate(ctx) assert.Equal(t, wfv1.WorkflowSucceeded, woc.wf.Status.Phase) - - _ = os.Unsetenv("DISABLE_MAX_RECURSION") } func TestGetChildNodeIdsAndLastRetriedNode(t *testing.T) { @@ -10661,7 +10653,7 @@ spec: script: image: python:alpine3.6 command: [python] - env: + env: - name: message value: "{{inputs.parameters.message}}" source: | diff --git a/workflow/controller/pod/significant_test.go b/workflow/controller/pod/significant_test.go index 1e7b5463d335..bc2d94c73718 100644 --- a/workflow/controller/pod/significant_test.go +++ b/workflow/controller/pod/significant_test.go @@ -1,7 +1,6 @@ package pod import ( - "os" "testing" "github.com/stretchr/testify/assert" @@ -14,8 +13,7 @@ func Test_SgnificantPodChange(t *testing.T) { assert.False(t, SignificantPodChange(&corev1.Pod{}, &corev1.Pod{})) }) t.Run("ALL_POD_CHANGES_SIGNIFICANT", func(t *testing.T) { - _ = os.Setenv("ALL_POD_CHANGES_SIGNIFICANT", "true") - defer func() { _ = os.Unsetenv("ALL_POD_CHANGES_SIGNIFICANT") }() + t.Setenv("ALL_POD_CHANGES_SIGNIFICANT", "true") assert.True(t, SignificantPodChange(&corev1.Pod{}, &corev1.Pod{})) }) t.Run("DeletionTimestamp", func(t *testing.T) { diff --git a/workflow/events/event_recorder_manager_test.go b/workflow/events/event_recorder_manager_test.go index 9fe642f4846d..6cd68c86edc1 100644 --- a/workflow/events/event_recorder_manager_test.go +++ b/workflow/events/event_recorder_manager_test.go @@ -1,7 +1,6 @@ package events import ( - "os" "testing" apiv1 "k8s.io/api/core/v1" @@ -31,17 +30,15 @@ func TestCustomEventAggregatorFuncWithAnnotations(t *testing.T) { assert.Equal(t, "component1host1name1", key) assert.Equal(t, "message1", msg) - _ = os.Setenv(aggregationWithAnnotationsEnvKey, "true") + t.Setenv(aggregationWithAnnotationsEnvKey, "true") key, msg = customEventAggregatorFuncWithAnnotations(&event) assert.Equal(t, "component1host1name1val1val2", key) assert.Equal(t, "message1", msg) // Test annotations with values in different order - _ = os.Setenv(aggregationWithAnnotationsEnvKey, "true") + t.Setenv(aggregationWithAnnotationsEnvKey, "true") event.ObjectMeta.Annotations = map[string]string{"key2": "val2", "key1": "val1"} key, msg = customEventAggregatorFuncWithAnnotations(&event) assert.Equal(t, "component1host1name1val1val2", key) assert.Equal(t, "message1", msg) - - _ = os.Unsetenv(aggregationWithAnnotationsEnvKey) } diff --git a/workflow/executor/resource_test.go b/workflow/executor/resource_test.go index f1513c9d848f..d3cd6b8d59c4 100644 --- a/workflow/executor/resource_test.go +++ b/workflow/executor/resource_test.go @@ -209,13 +209,11 @@ func TestResourceExecRetry(t *testing.T) { _, filename, _, _ := runtime.Caller(0) dirname := path.Dir(filename) duration := retry.DefaultBackoff.Duration - path := os.Getenv("PATH") defer func() { - os.Setenv("PATH", path) retry.DefaultBackoff.Duration = duration }() retry.DefaultBackoff.Duration = 0 - os.Setenv("PATH", dirname+"/testdata") + t.Setenv("PATH", dirname+"/testdata") _, _, _, err := we.ExecResource("", "../../examples/hello-world.yaml", nil) assert.Error(t, err)