diff --git a/cmd/argoexec/commands/emissary_test.go b/cmd/argoexec/commands/emissary_test.go index 3313e0e789f4..946d728a529e 100644 --- a/cmd/argoexec/commands/emissary_test.go +++ b/cmd/argoexec/commands/emissary_test.go @@ -75,7 +75,7 @@ func TestEmissary(t *testing.T) { go func() { defer wg.Done() err := run("sleep 3") - assert.EqualError(t, err, fmt.Sprintf("exit status %d", 128+signal)) + require.EqualError(t, err, fmt.Sprintf("exit status %d", 128+signal)) }() wg.Wait() } diff --git a/server/artifacts/artifact_server_test.go b/server/artifacts/artifact_server_test.go index 999a98d616e6..3501a1169f0e 100644 --- a/server/artifacts/artifact_server_test.go +++ b/server/artifacts/artifact_server_test.go @@ -19,6 +19,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kubefake "k8s.io/client-go/kubernetes/fake" @@ -664,14 +665,14 @@ func TestArtifactServer_GetArtifactByUIDInvalidRequestPath(t *testing.T) { // make sure there is no index out of bounds error assert.Equal(t, 400, recorder.Result().StatusCode) output, err := io.ReadAll(recorder.Result().Body) - assert.NoError(t, err) + require.NoError(t, err) assert.Contains(t, string(output), "Bad Request") recorder = httptest.NewRecorder() s.GetOutputArtifactByUID(recorder, r) assert.Equal(t, 400, recorder.Result().StatusCode) output, err = io.ReadAll(recorder.Result().Body) - assert.NoError(t, err) + require.NoError(t, err) assert.Contains(t, string(output), "Bad Request") } @@ -682,7 +683,7 @@ func TestArtifactServer_httpBadRequestError(t *testing.T) { assert.Equal(t, http.StatusBadRequest, recorder.Result().StatusCode) output, err := io.ReadAll(recorder.Result().Body) - assert.NoError(t, err) + require.NoError(t, err) assert.Contains(t, string(output), "Bad Request") } @@ -695,7 +696,7 @@ func TestArtifactServer_httpFromError(t *testing.T) { assert.Equal(t, http.StatusInternalServerError, recorder.Result().StatusCode) output, err := io.ReadAll(recorder.Result().Body) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, "Internal Server Error\n", string(output)) recorder = httptest.NewRecorder() @@ -705,7 +706,7 @@ func TestArtifactServer_httpFromError(t *testing.T) { assert.Equal(t, http.StatusUnauthorized, recorder.Result().StatusCode) output, err = io.ReadAll(recorder.Result().Body) - assert.NoError(t, err) + require.NoError(t, err) assert.Contains(t, string(output), "Unauthorized") recorder = httptest.NewRecorder() diff --git a/server/auth/authorizer_test.go b/server/auth/authorizer_test.go index 1d67fd63583a..364e9389dd82 100644 --- a/server/auth/authorizer_test.go +++ b/server/auth/authorizer_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" authorizationv1 "k8s.io/api/authorization/v1" "k8s.io/apimachinery/pkg/runtime" kubefake "k8s.io/client-go/kubernetes/fake" @@ -22,9 +23,8 @@ func TestAuthorizer_CanI(t *testing.T) { ctx := context.WithValue(context.Background(), KubeKey, kubeClient) t.Run("CanI", func(t *testing.T) { allowed, err := CanI(ctx, "", "", "", "") - if assert.NoError(t, err) { - assert.True(t, allowed) - } + require.NoError(t, err) + assert.True(t, allowed) }) kubeClient.AddReactor("create", "selfsubjectrulesreviews", func(action k8stesting.Action) (handled bool, ret runtime.Object, err error) { return true, &authorizationv1.SelfSubjectRulesReview{ diff --git a/server/auth/gatekeeper_test.go b/server/auth/gatekeeper_test.go index 755727ad7b1a..fe938d1dc0ea 100644 --- a/server/auth/gatekeeper_test.go +++ b/server/auth/gatekeeper_test.go @@ -9,6 +9,7 @@ import ( "github.com/sirupsen/logrus/hooks/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" "google.golang.org/grpc/metadata" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -111,56 +112,50 @@ func TestServer_GetWFClient(t *testing.T) { clients := &servertypes.Clients{Workflow: wfClient, Kubernetes: kubeClient} t.Run("None", func(t *testing.T) { _, err := NewGatekeeper(Modes{}, clients, nil, nil, clientForAuthorization, "", "", true, resourceCache) - assert.Error(t, err) + require.Error(t, err) }) t.Run("Invalid", func(t *testing.T) { g, err := NewGatekeeper(Modes{Client: true}, clients, nil, nil, clientForAuthorization, "", "", true, resourceCache) - if assert.NoError(t, err) { - _, err := g.Context(x("invalid")) - assert.Error(t, err) - } + require.NoError(t, err) + _, err = g.Context(x("invalid")) + require.Error(t, err) }) t.Run("NotAllowed", func(t *testing.T) { g, err := NewGatekeeper(Modes{SSO: true}, clients, nil, nil, clientForAuthorization, "", "", true, resourceCache) - if assert.NoError(t, err) { - _, err := g.Context(x("Bearer ")) - assert.Error(t, err) - } + require.NoError(t, err) + _, err = g.Context(x("Bearer ")) + require.Error(t, err) }) t.Run("Client", func(t *testing.T) { g, err := NewGatekeeper(Modes{Client: true}, clients, &rest.Config{Username: "my-username"}, nil, clientForAuthorization, "", "", true, resourceCache) - assert.NoError(t, err) + require.NoError(t, err) ctx, err := g.Context(x("Bearer ")) - if assert.NoError(t, err) { - assert.NotEqual(t, wfClient, GetWfClient(ctx)) - assert.NotEqual(t, kubeClient, GetKubeClient(ctx)) - assert.Nil(t, GetClaims(ctx)) - } + require.NoError(t, err) + assert.NotEqual(t, wfClient, GetWfClient(ctx)) + assert.NotEqual(t, kubeClient, GetKubeClient(ctx)) + assert.Nil(t, GetClaims(ctx)) }) t.Run("Server", func(t *testing.T) { g, err := NewGatekeeper(Modes{Server: true}, clients, &rest.Config{Username: "my-username"}, nil, clientForAuthorization, "", "", true, resourceCache) - assert.NoError(t, err) + require.NoError(t, err) ctx, err := g.Context(x("")) - if assert.NoError(t, err) { - assert.Equal(t, wfClient, GetWfClient(ctx)) - assert.Equal(t, kubeClient, GetKubeClient(ctx)) - assert.NotNil(t, GetClaims(ctx)) - } + require.NoError(t, err) + assert.Equal(t, wfClient, GetWfClient(ctx)) + assert.Equal(t, kubeClient, GetKubeClient(ctx)) + assert.NotNil(t, GetClaims(ctx)) }) t.Run("SSO", func(t *testing.T) { ssoIf := &ssomocks.Interface{} ssoIf.On("Authorize", mock.Anything, mock.Anything).Return(&types.Claims{Claims: jwt.Claims{Subject: "my-sub"}}, nil) ssoIf.On("IsRBACEnabled").Return(false) g, err := NewGatekeeper(Modes{SSO: true}, clients, &rest.Config{Username: "my-username"}, ssoIf, clientForAuthorization, "my-ns", "my-ns", true, resourceCache) - if assert.NoError(t, err) { - ctx, err := g.Context(x("Bearer v2:whatever")) - if assert.NoError(t, err) { - assert.Equal(t, wfClient, GetWfClient(ctx)) - assert.Equal(t, kubeClient, GetKubeClient(ctx)) - if assert.NotNil(t, GetClaims(ctx)) { - assert.Equal(t, "my-sub", GetClaims(ctx).Subject) - } - } + require.NoError(t, err) + ctx, err := g.Context(x("Bearer v2:whatever")) + require.NoError(t, err) + assert.Equal(t, wfClient, GetWfClient(ctx)) + assert.Equal(t, kubeClient, GetKubeClient(ctx)) + if assert.NotNil(t, GetClaims(ctx)) { + assert.Equal(t, "my-sub", GetClaims(ctx).Subject) } }) hook := &test.Hook{} @@ -171,20 +166,18 @@ func TestServer_GetWFClient(t *testing.T) { ssoIf.On("Authorize", mock.Anything, mock.Anything).Return(&types.Claims{Groups: []string{"my-group", "other-group"}}, nil) ssoIf.On("IsRBACEnabled").Return(true) g, err := NewGatekeeper(Modes{SSO: true}, clients, &rest.Config{Username: "my-username"}, ssoIf, clientForAuthorization, "my-ns", "my-ns", true, resourceCache) - if assert.NoError(t, err) { - ctx, err := g.Context(x("Bearer v2:whatever")) - if assert.NoError(t, err) { - assert.NotEqual(t, clients, GetWfClient(ctx)) - assert.NotEqual(t, kubeClient, GetKubeClient(ctx)) - claims := GetClaims(ctx) - if assert.NotNil(t, claims) { - assert.Equal(t, []string{"my-group", "other-group"}, claims.Groups) - assert.Equal(t, "my-sa", claims.ServiceAccountName) - assert.Equal(t, "my-ns", claims.ServiceAccountNamespace) - } - assert.Equal(t, "my-sa", hook.LastEntry().Data["serviceAccount"]) - } + require.NoError(t, err) + ctx, err := g.Context(x("Bearer v2:whatever")) + require.NoError(t, err) + assert.NotEqual(t, clients, GetWfClient(ctx)) + assert.NotEqual(t, kubeClient, GetKubeClient(ctx)) + claims := GetClaims(ctx) + if assert.NotNil(t, claims) { + assert.Equal(t, []string{"my-group", "other-group"}, claims.Groups) + assert.Equal(t, "my-sa", claims.ServiceAccountName) + assert.Equal(t, "my-ns", claims.ServiceAccountNamespace) } + assert.Equal(t, "my-sa", hook.LastEntry().Data["serviceAccount"]) }) t.Run("SSO+RBAC, Namespace delegation ON, precedence=2, Delegated", func(t *testing.T) { t.Setenv("SSO_DELEGATE_RBAC_TO_NAMESPACE", "true") @@ -192,40 +185,36 @@ func TestServer_GetWFClient(t *testing.T) { ssoIf.On("Authorize", mock.Anything, mock.Anything).Return(&types.Claims{Groups: []string{"my-group", "other-group"}}, nil) ssoIf.On("IsRBACEnabled").Return(true) g, err := NewGatekeeper(Modes{SSO: true}, clients, &rest.Config{Username: "my-username"}, ssoIf, clientForAuthorization, "my-ns", "my-ns", false, resourceCache) - if assert.NoError(t, err) { - ctx, err := g.ContextWithRequest(x("Bearer v2:whatever"), servertypes.NamespaceHolder("user1-ns")) - if assert.NoError(t, err) { - assert.NotEqual(t, clients, GetWfClient(ctx)) - assert.NotEqual(t, kubeClient, GetKubeClient(ctx)) - claims := GetClaims(ctx) - if assert.NotNil(t, claims) { - assert.Equal(t, []string{"my-group", "other-group"}, claims.Groups) - assert.Equal(t, "user1-sa", claims.ServiceAccountName) - assert.Equal(t, "user1-ns", claims.ServiceAccountNamespace) - } - assert.Equal(t, "user1-sa", hook.LastEntry().Data["serviceAccount"]) - } + require.NoError(t, err) + ctx, err := g.ContextWithRequest(x("Bearer v2:whatever"), servertypes.NamespaceHolder("user1-ns")) + require.NoError(t, err) + assert.NotEqual(t, clients, GetWfClient(ctx)) + assert.NotEqual(t, kubeClient, GetKubeClient(ctx)) + claims := GetClaims(ctx) + if assert.NotNil(t, claims) { + assert.Equal(t, []string{"my-group", "other-group"}, claims.Groups) + assert.Equal(t, "user1-sa", claims.ServiceAccountName) + assert.Equal(t, "user1-ns", claims.ServiceAccountNamespace) } + assert.Equal(t, "user1-sa", hook.LastEntry().Data["serviceAccount"]) }) t.Run("SSO+RBAC, Namespace delegation OFF, precedence=2, Not Delegated", func(t *testing.T) { 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) g, err := NewGatekeeper(Modes{SSO: true}, clients, &rest.Config{Username: "my-username"}, ssoIf, clientForAuthorization, "my-ns", "my-ns", true, resourceCache) - if assert.NoError(t, err) { - ctx, err := g.ContextWithRequest(x("Bearer v2:whatever"), servertypes.NamespaceHolder("user1-ns")) - if assert.NoError(t, err) { - assert.NotEqual(t, clients, GetWfClient(ctx)) - assert.NotEqual(t, kubeClient, GetKubeClient(ctx)) - claims := GetClaims(ctx) - if assert.NotNil(t, claims) { - assert.Equal(t, []string{"my-group", "other-group"}, claims.Groups) - assert.Equal(t, "my-sa", claims.ServiceAccountName) - assert.Equal(t, "my-ns", claims.ServiceAccountNamespace) - } - assert.Equal(t, "my-sa", hook.LastEntry().Data["serviceAccount"]) - } + require.NoError(t, err) + ctx, err := g.ContextWithRequest(x("Bearer v2:whatever"), servertypes.NamespaceHolder("user1-ns")) + require.NoError(t, err) + assert.NotEqual(t, clients, GetWfClient(ctx)) + assert.NotEqual(t, kubeClient, GetKubeClient(ctx)) + claims := GetClaims(ctx) + if assert.NotNil(t, claims) { + assert.Equal(t, []string{"my-group", "other-group"}, claims.Groups) + assert.Equal(t, "my-sa", claims.ServiceAccountName) + assert.Equal(t, "my-ns", claims.ServiceAccountNamespace) } + assert.Equal(t, "my-sa", hook.LastEntry().Data["serviceAccount"]) }) t.Run("SSO+RBAC, Namespace delegation ON, precedence=0, Not delegated", func(t *testing.T) { t.Setenv("SSO_DELEGATE_RBAC_TO_NAMESPACE", "true") @@ -233,20 +222,18 @@ func TestServer_GetWFClient(t *testing.T) { ssoIf.On("Authorize", mock.Anything, mock.Anything).Return(&types.Claims{Groups: []string{"my-group", "other-group"}}, nil) ssoIf.On("IsRBACEnabled").Return(true) g, err := NewGatekeeper(Modes{SSO: true}, clients, &rest.Config{Username: "my-username"}, ssoIf, clientForAuthorization, "my-ns", "my-ns", false, resourceCache) - if assert.NoError(t, err) { - ctx, err := g.ContextWithRequest(x("Bearer v2:whatever"), servertypes.NamespaceHolder("user2-ns")) - if assert.NoError(t, err) { - assert.NotEqual(t, clients, GetWfClient(ctx)) - assert.NotEqual(t, kubeClient, GetKubeClient(ctx)) - claims := GetClaims(ctx) - if assert.NotNil(t, claims) { - assert.Equal(t, []string{"my-group", "other-group"}, claims.Groups) - assert.Equal(t, "my-sa", claims.ServiceAccountName) - assert.Equal(t, "my-ns", claims.ServiceAccountNamespace) - } - assert.Equal(t, "my-sa", hook.LastEntry().Data["serviceAccount"]) - } + require.NoError(t, err) + ctx, err := g.ContextWithRequest(x("Bearer v2:whatever"), servertypes.NamespaceHolder("user2-ns")) + require.NoError(t, err) + assert.NotEqual(t, clients, GetWfClient(ctx)) + assert.NotEqual(t, kubeClient, GetKubeClient(ctx)) + claims := GetClaims(ctx) + if assert.NotNil(t, claims) { + assert.Equal(t, []string{"my-group", "other-group"}, claims.Groups) + assert.Equal(t, "my-sa", claims.ServiceAccountName) + assert.Equal(t, "my-ns", claims.ServiceAccountNamespace) } + assert.Equal(t, "my-sa", hook.LastEntry().Data["serviceAccount"]) }) t.Run("SSO+RBAC, Namespace delegation ON, precedence=1, Not delegated", func(t *testing.T) { t.Setenv("SSO_DELEGATE_RBAC_TO_NAMESPACE", "true") @@ -254,43 +241,38 @@ func TestServer_GetWFClient(t *testing.T) { ssoIf.On("Authorize", mock.Anything, mock.Anything).Return(&types.Claims{Groups: []string{"my-group", "other-group"}}, nil) ssoIf.On("IsRBACEnabled").Return(true) g, err := NewGatekeeper(Modes{SSO: true}, clients, &rest.Config{Username: "my-username"}, ssoIf, clientForAuthorization, "my-ns", "my-ns", false, resourceCache) - if assert.NoError(t, err) { - ctx, err := g.ContextWithRequest(x("Bearer v2:whatever"), servertypes.NamespaceHolder("user3-ns")) - if assert.NoError(t, err) { - assert.NotEqual(t, clients, GetWfClient(ctx)) - assert.NotEqual(t, kubeClient, GetKubeClient(ctx)) - claims := GetClaims(ctx) - if assert.NotNil(t, claims) { - assert.Equal(t, []string{"my-group", "other-group"}, claims.Groups) - assert.Equal(t, "my-sa", claims.ServiceAccountName) - assert.Equal(t, "my-ns", claims.ServiceAccountNamespace) - } - assert.Equal(t, "my-sa", hook.LastEntry().Data["serviceAccount"]) - } + require.NoError(t, err) + ctx, err := g.ContextWithRequest(x("Bearer v2:whatever"), servertypes.NamespaceHolder("user3-ns")) + require.NoError(t, err) + assert.NotEqual(t, clients, GetWfClient(ctx)) + assert.NotEqual(t, kubeClient, GetKubeClient(ctx)) + claims := GetClaims(ctx) + if assert.NotNil(t, claims) { + assert.Equal(t, []string{"my-group", "other-group"}, claims.Groups) + assert.Equal(t, "my-sa", claims.ServiceAccountName) + assert.Equal(t, "my-ns", claims.ServiceAccountNamespace) } + assert.Equal(t, "my-sa", hook.LastEntry().Data["serviceAccount"]) }) t.Run("SSO+RBAC,precedence=0", func(t *testing.T) { ssoIf := &ssomocks.Interface{} ssoIf.On("Authorize", mock.Anything, mock.Anything).Return(&types.Claims{Groups: []string{"other-group"}}, nil) ssoIf.On("IsRBACEnabled").Return(true) g, err := NewGatekeeper(Modes{SSO: true}, clients, &rest.Config{Username: "my-username"}, ssoIf, clientForAuthorization, "my-ns", "my-ns", true, resourceCache) - if assert.NoError(t, err) { - ctx, err := g.Context(x("Bearer v2:whatever")) - if assert.NoError(t, err) { - assert.Equal(t, "my-other-sa", hook.LastEntry().Data["serviceAccount"]) - assert.Equal(t, "my-other-sa", GetClaims(ctx).ServiceAccountName) - } - } + require.NoError(t, err) + ctx, err := g.Context(x("Bearer v2:whatever")) + require.NoError(t, err) + assert.Equal(t, "my-other-sa", hook.LastEntry().Data["serviceAccount"]) + assert.Equal(t, "my-other-sa", GetClaims(ctx).ServiceAccountName) }) t.Run("SSO+RBAC,denied", func(t *testing.T) { ssoIf := &ssomocks.Interface{} ssoIf.On("Authorize", mock.Anything, mock.Anything).Return(&types.Claims{}, nil) ssoIf.On("IsRBACEnabled").Return(true) g, err := NewGatekeeper(Modes{SSO: true}, clients, &rest.Config{Username: "my-username"}, ssoIf, clientForAuthorization, "my-ns", "my-ns", true, resourceCache) - if assert.NoError(t, err) { - _, err := g.Context(x("Bearer v2:whatever")) - assert.EqualError(t, err, "rpc error: code = PermissionDenied desc = not allowed") - } + require.NoError(t, err) + _, err = g.Context(x("Bearer v2:whatever")) + require.EqualError(t, err, "rpc error: code = PermissionDenied desc = not allowed") }) } diff --git a/server/auth/mode_test.go b/server/auth/mode_test.go index 07f593cad87a..8d9ce8ef9158 100644 --- a/server/auth/mode_test.go +++ b/server/auth/mode_test.go @@ -4,36 +4,33 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestModes_Add(t *testing.T) { t.Run("InvalidMode", func(t *testing.T) { - assert.Error(t, Modes{}.Add("")) + require.Error(t, Modes{}.Add("")) }) t.Run("Client", func(t *testing.T) { m := Modes{} - if assert.NoError(t, m.Add("client")) { - assert.Contains(t, m, Client) - } + require.NoError(t, m.Add("client")) + assert.Contains(t, m, Client) }) t.Run("Hybrid", func(t *testing.T) { m := Modes{} - if assert.NoError(t, m.Add("hybrid")) { - assert.Contains(t, m, Client) - assert.Contains(t, m, Server) - } + require.NoError(t, m.Add("hybrid")) + assert.Contains(t, m, Client) + assert.Contains(t, m, Server) }) t.Run("Server", func(t *testing.T) { m := Modes{} - if assert.NoError(t, m.Add("server")) { - assert.Contains(t, m, Server) - } + require.NoError(t, m.Add("server")) + assert.Contains(t, m, Server) }) t.Run("SSO", func(t *testing.T) { m := Modes{} - if assert.NoError(t, m.Add("sso")) { - assert.Contains(t, m, SSO) - } + require.NoError(t, m.Add("sso")) + assert.Contains(t, m, SSO) }) } diff --git a/server/auth/serviceaccount/claims_test.go b/server/auth/serviceaccount/claims_test.go index e53e2dd097b0..f9f6bfe2d9a2 100644 --- a/server/auth/serviceaccount/claims_test.go +++ b/server/auth/serviceaccount/claims_test.go @@ -21,43 +21,39 @@ const token2 = "eyJhbGciOiJSUzI1NiIsImtpZCI6Ijc5dVprMUl0VHZkTXFpLWc4dVQwVkV1Y05U func TestClaimSetFor(t *testing.T) { t.Run("Empty", func(t *testing.T) { claims, err := ClaimSetFor(&rest.Config{}) - if assert.NoError(t, err) { - assert.Nil(t, claims) - } + require.NoError(t, err) + assert.Nil(t, claims) }) t.Run("Basic", func(t *testing.T) { const username = "my-username" claims, err := ClaimSetFor(&rest.Config{Username: username}) - if assert.NoError(t, err) { - assert.Empty(t, claims.Issuer) - assert.Equal(t, username, claims.Subject) - } + require.NoError(t, err) + assert.Empty(t, claims.Issuer) + assert.Equal(t, username, claims.Subject) }) t.Run("BadBearerToken", func(t *testing.T) { _, err := ClaimSetFor(&rest.Config{BearerToken: "bad"}) - assert.Error(t, err) + require.Error(t, err) }) t.Run("BearerToken", func(t *testing.T) { claims, err := ClaimSetFor(&rest.Config{BearerToken: token}) - if assert.NoError(t, err) { - assert.Empty(t, claims.Issuer) - assert.Equal(t, sub, claims.Subject) - } + require.NoError(t, err) + assert.Empty(t, claims.Issuer) + assert.Equal(t, sub, claims.Subject) }) // set-up test tmp, err := os.CreateTemp("", "") - assert.NoError(t, err) + require.NoError(t, err) err = os.WriteFile(tmp.Name(), []byte(token), 0o600) - assert.NoError(t, err) + require.NoError(t, err) defer func() { _ = os.Remove(tmp.Name()) }() t.Run("BearerTokenFile", func(t *testing.T) { claims, err := ClaimSetFor(&rest.Config{BearerTokenFile: tmp.Name()}) - if assert.NoError(t, err) { - assert.Empty(t, claims.Issuer) - assert.Equal(t, sub, claims.Subject) - } + require.NoError(t, err) + assert.Empty(t, claims.Issuer) + assert.Equal(t, sub, claims.Subject) }) t.Run("BearerToken with SA details", func(t *testing.T) { diff --git a/server/auth/sso/null_sso_test.go b/server/auth/sso/null_sso_test.go index 105ba34f5715..c3ca4f2489dc 100644 --- a/server/auth/sso/null_sso_test.go +++ b/server/auth/sso/null_sso_test.go @@ -6,11 +6,12 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func Test_nullSSO_Authorize(t *testing.T) { _, err := NullSSO.Authorize("") - assert.Error(t, err) + require.Error(t, err) } func Test_nullSSO_HandleCallback(t *testing.T) { diff --git a/server/auth/sso/sso_test.go b/server/auth/sso/sso_test.go index f6af6bea4421..217266061f4c 100644 --- a/server/auth/sso/sso_test.go +++ b/server/auth/sso/sso_test.go @@ -7,6 +7,7 @@ import ( "github.com/coreos/go-oidc/v3/oidc" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "golang.org/x/oauth2" apiv1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -64,7 +65,7 @@ func TestLoadSsoClientIdFromSecret(t *testing.T) { CustomGroupClaimName: "argo_groups", } ssoInterface, err := newSso(fakeOidcFactory, config, fakeClient, "/", false) - assert.NoError(t, err) + require.NoError(t, err) ssoObject := ssoInterface.(*sso) assert.Equal(t, "sso-client-id-value", ssoObject.config.ClientID) assert.Equal(t, "sso-client-secret-value", ssoObject.config.ClientSecret) @@ -85,7 +86,7 @@ func TestNewSsoWithIssuerAlias(t *testing.T) { CustomGroupClaimName: "argo_groups", } _, err := newSso(fakeOidcFactory, config, fakeClient, "/", false) - assert.NoError(t, err) + require.NoError(t, err) } func TestLoadSsoClientIdFromDifferentSecret(t *testing.T) { @@ -108,7 +109,7 @@ func TestLoadSsoClientIdFromDifferentSecret(t *testing.T) { RedirectURL: "https://dummy", } ssoInterface, err := newSso(fakeOidcFactory, config, fakeClient, "/", false) - assert.NoError(t, err) + require.NoError(t, err) ssoObject := ssoInterface.(*sso) assert.Equal(t, "sso-client-id-value", ssoObject.config.ClientID) } @@ -122,7 +123,7 @@ func TestLoadSsoClientIdFromSecretNoKeyFails(t *testing.T) { RedirectURL: "https://dummy", } _, err := newSso(fakeOidcFactory, config, fakeClient, "/", false) - assert.Error(t, err) + require.Error(t, err) assert.Regexp(t, "key nonexistent missing in secret argo-sso-secret", err.Error()) } @@ -134,7 +135,7 @@ func TestLoadSsoClientIdFromExistingSsoSecretFails(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: secretName}, Data: map[string][]byte{}, }, metav1.CreateOptions{}) - assert.NoError(t, err) + require.NoError(t, err) config := Config{ Issuer: "https://test-issuer", @@ -143,7 +144,7 @@ func TestLoadSsoClientIdFromExistingSsoSecretFails(t *testing.T) { RedirectURL: "https://dummy", } _, err = newSso(fakeOidcFactory, config, fakeClient, "/", false) - assert.Error(t, err) + require.Error(t, err) assert.Regexp(t, "If you have already defined a Secret named sso, delete it and retry", err.Error()) } diff --git a/server/auth/types/claims_test.go b/server/auth/types/claims_test.go index 4c2ccee5ab14..37383fefae2a 100644 --- a/server/auth/types/claims_test.go +++ b/server/auth/types/claims_test.go @@ -9,6 +9,7 @@ import ( "github.com/go-jose/go-jose/v3/jwt" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestUnmarshalJSON(t *testing.T) { @@ -180,9 +181,7 @@ func TestGetCustomGroup(t *testing.T) { t.Run("NoCustomGroupSet", func(t *testing.T) { claims := &Claims{} _, err := claims.GetCustomGroup(("ad_groups")) - if assert.Error(t, err) { - assert.EqualError(t, err, "no claim found for key: ad_groups") - } + require.EqualError(t, err, "no claim found for key: ad_groups") }) t.Run("CustomGroupSet", func(t *testing.T) { tGroup := []string{"my-group"} @@ -194,9 +193,8 @@ func TestGetCustomGroup(t *testing.T) { "ad_groups": tGroupsIf, }} groups, err := claims.GetCustomGroup(("ad_groups")) - if assert.NoError(t, err) { - assert.Equal(t, []string{"my-group"}, groups) - } + require.NoError(t, err) + assert.Equal(t, []string{"my-group"}, groups) }) t.Run("CustomGroupNotString", func(t *testing.T) { tGroup := []int{0} @@ -208,9 +206,7 @@ func TestGetCustomGroup(t *testing.T) { "ad_groups": tGroupsIf, }} _, err := claims.GetCustomGroup(("ad_groups")) - if assert.Error(t, err) { - assert.EqualError(t, err, "group name 0 was not a string") - } + require.EqualError(t, err, "group name 0 was not a string") }) t.Run("CustomGroupNotSlice", func(t *testing.T) { tGroup := "None" @@ -218,7 +214,7 @@ func TestGetCustomGroup(t *testing.T) { "ad_groups": tGroup, }} _, err := claims.GetCustomGroup(("ad_groups")) - assert.Error(t, err) + require.Error(t, err) }) } @@ -245,6 +241,6 @@ func TestGetUserInfoGroups(t *testing.T) { claims := &Claims{} groups, err := claims.GetUserInfoGroups(httpClient, "Bearer fake", "https://fake.okta.com", "/user-info") assert.Equal(t, []string{"Everyone"}, groups) - assert.NoError(t, err) + require.NoError(t, err) }) } diff --git a/server/clusterworkflowtemplate/cluster_workflow_template_server_test.go b/server/clusterworkflowtemplate/cluster_workflow_template_server_test.go index 794d0eea5995..d45e8a875db8 100644 --- a/server/clusterworkflowtemplate/cluster_workflow_template_server_test.go +++ b/server/clusterworkflowtemplate/cluster_workflow_template_server_test.go @@ -6,6 +6,7 @@ import ( "github.com/go-jose/go-jose/v3/jwt" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "k8s.io/client-go/kubernetes/fake" clusterwftmplpkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/clusterworkflowtemplate" @@ -162,10 +163,9 @@ func TestWorkflowTemplateServer_CreateClusterWorkflowTemplate(t *testing.T) { Template: tmpl, } resp, err := server.CreateClusterWorkflowTemplate(ctx, &req) - if assert.NoError(t, err) { - assert.Equal(t, "message", resp.Spec.Arguments.Parameters[0].Name) - assert.Nil(t, resp.Spec.Arguments.Parameters[0].Value) - } + require.NoError(t, err) + assert.Equal(t, "message", resp.Spec.Arguments.Parameters[0].Name) + assert.Nil(t, resp.Spec.Arguments.Parameters[0].Value) }) t.Run("With parameter values", func(t *testing.T) { cwftReq := clusterwftmplpkg.ClusterWorkflowTemplateCreateRequest{ @@ -174,12 +174,11 @@ func TestWorkflowTemplateServer_CreateClusterWorkflowTemplate(t *testing.T) { cwftReq.Template.Name = "foo-with-param-values" assert.NotContains(t, cwftReq.Template.Labels, common.LabelKeyControllerInstanceID) cwftRsp, err := server.CreateClusterWorkflowTemplate(ctx, &cwftReq) - if assert.NoError(t, err) { - assert.NotNil(t, cwftRsp) - // ensure the label is added - assert.Contains(t, cwftRsp.Labels, common.LabelKeyControllerInstanceID) - assert.Contains(t, cwftRsp.Labels, common.LabelKeyCreator) - } + require.NoError(t, err) + assert.NotNil(t, cwftRsp) + // ensure the label is added + assert.Contains(t, cwftRsp.Labels, common.LabelKeyControllerInstanceID) + assert.Contains(t, cwftRsp.Labels, common.LabelKeyCreator) }) } @@ -189,17 +188,16 @@ func TestWorkflowTemplateServer_GetClusterWorkflowTemplate(t *testing.T) { cwftRsp, err := server.GetClusterWorkflowTemplate(ctx, &clusterwftmplpkg.ClusterWorkflowTemplateGetRequest{ Name: "cluster-workflow-template-whalesay-template2", }) - if assert.NoError(t, err) { - assert.NotNil(t, cwftRsp) - assert.Equal(t, "cluster-workflow-template-whalesay-template2", cwftRsp.Name) - assert.Contains(t, cwftRsp.Labels, common.LabelKeyControllerInstanceID) - } + require.NoError(t, err) + assert.NotNil(t, cwftRsp) + assert.Equal(t, "cluster-workflow-template-whalesay-template2", cwftRsp.Name) + assert.Contains(t, cwftRsp.Labels, common.LabelKeyControllerInstanceID) }) t.Run("Unlabelled", func(t *testing.T) { _, err := server.GetClusterWorkflowTemplate(ctx, &clusterwftmplpkg.ClusterWorkflowTemplateGetRequest{ Name: "cluster-workflow-template-whalesay-template", }) - assert.Error(t, err) + require.Error(t, err) }) } @@ -207,11 +205,10 @@ func TestWorkflowTemplateServer_ListClusterWorkflowTemplates(t *testing.T) { server, ctx := getClusterWorkflowTemplateServer() cwftReq := clusterwftmplpkg.ClusterWorkflowTemplateListRequest{} cwftRsp, err := server.ListClusterWorkflowTemplates(ctx, &cwftReq) - if assert.NoError(t, err) { - assert.Len(t, cwftRsp.Items, 2) - for _, item := range cwftRsp.Items { - assert.Contains(t, item.Labels, common.LabelKeyControllerInstanceID) - } + require.NoError(t, err) + assert.Len(t, cwftRsp.Items, 2) + for _, item := range cwftRsp.Items { + assert.Contains(t, item.Labels, common.LabelKeyControllerInstanceID) } } @@ -221,13 +218,13 @@ func TestWorkflowTemplateServer_DeleteClusterWorkflowTemplate(t *testing.T) { _, err := server.DeleteClusterWorkflowTemplate(ctx, &clusterwftmplpkg.ClusterWorkflowTemplateDeleteRequest{ Name: "cluster-workflow-template-whalesay-template2", }) - assert.NoError(t, err) + require.NoError(t, err) }) t.Run("Unlabelled", func(t *testing.T) { _, err := server.DeleteClusterWorkflowTemplate(ctx, &clusterwftmplpkg.ClusterWorkflowTemplateDeleteRequest{ Name: "cluster-workflow-template-whalesay-template", }) - assert.Error(t, err) + require.Error(t, err) }) } @@ -238,10 +235,9 @@ func TestWorkflowTemplateServer_LintClusterWorkflowTemplate(t *testing.T) { resp, err := server.LintClusterWorkflowTemplate(ctx, &clusterwftmplpkg.ClusterWorkflowTemplateLintRequest{ Template: &cwftObj1, }) - if assert.NoError(t, err) { - assert.Contains(t, resp.Labels, common.LabelKeyControllerInstanceID) - assert.Contains(t, resp.Labels, common.LabelKeyCreator) - } + require.NoError(t, err) + assert.Contains(t, resp.Labels, common.LabelKeyControllerInstanceID) + assert.Contains(t, resp.Labels, common.LabelKeyCreator) }) t.Run("Without param values", func(t *testing.T) { @@ -252,10 +248,9 @@ func TestWorkflowTemplateServer_LintClusterWorkflowTemplate(t *testing.T) { Template: tmpl, } resp, err := server.LintClusterWorkflowTemplate(ctx, &req) - if assert.NoError(t, err) { - assert.Equal(t, "message", resp.Spec.Arguments.Parameters[0].Name) - assert.Nil(t, resp.Spec.Arguments.Parameters[0].Value) - } + require.NoError(t, err) + assert.Equal(t, "message", resp.Spec.Arguments.Parameters[0].Name) + assert.Nil(t, resp.Spec.Arguments.Parameters[0].Value) }) } @@ -267,14 +262,13 @@ func TestWorkflowTemplateServer_UpdateClusterWorkflowTemplate(t *testing.T) { } req.Template.Spec.Templates[0].Container.Image = "alpine:latest" cwftRsp, err := server.UpdateClusterWorkflowTemplate(ctx, req) - if assert.NoError(t, err) { - assert.Equal(t, "alpine:latest", cwftRsp.Spec.Templates[0].Container.Image) - } + require.NoError(t, err) + assert.Equal(t, "alpine:latest", cwftRsp.Spec.Templates[0].Container.Image) }) t.Run("Unlabelled", func(t *testing.T) { _, err := server.UpdateClusterWorkflowTemplate(ctx, &clusterwftmplpkg.ClusterWorkflowTemplateUpdateRequest{ Template: &unlabelled, }) - assert.Error(t, err) + require.Error(t, err) }) } diff --git a/server/cronworkflow/cron_workflow_server_test.go b/server/cronworkflow/cron_workflow_server_test.go index 6e1a1dd94fc1..3a2adf261675 100644 --- a/server/cronworkflow/cron_workflow_server_test.go +++ b/server/cronworkflow/cron_workflow_server_test.go @@ -6,6 +6,7 @@ import ( "github.com/go-jose/go-jose/v3/jwt" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" cronworkflowpkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/cronworkflow" wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" @@ -59,39 +60,35 @@ metadata: Namespace: "my-ns", CronWorkflow: &cronWf, }) - if assert.NoError(t, err) { - assert.NotNil(t, created) - assert.Contains(t, created.Labels, common.LabelKeyControllerInstanceID) - assert.Contains(t, created.Labels, common.LabelKeyCreator) - } + require.NoError(t, err) + assert.NotNil(t, created) + assert.Contains(t, created.Labels, common.LabelKeyControllerInstanceID) + assert.Contains(t, created.Labels, common.LabelKeyCreator) }) t.Run("LintWorkflow", func(t *testing.T) { wf, err := server.LintCronWorkflow(ctx, &cronworkflowpkg.LintCronWorkflowRequest{ Namespace: "my-ns", CronWorkflow: &cronWf, }) - if assert.NoError(t, err) { - assert.NotNil(t, wf) - assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID) - assert.Contains(t, wf.Labels, common.LabelKeyCreator) - } + require.NoError(t, err) + assert.NotNil(t, wf) + assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID) + assert.Contains(t, wf.Labels, common.LabelKeyCreator) }) t.Run("ListCronWorkflows", func(t *testing.T) { cronWfs, err := server.ListCronWorkflows(ctx, &cronworkflowpkg.ListCronWorkflowsRequest{Namespace: "my-ns"}) - if assert.NoError(t, err) { - assert.Len(t, cronWfs.Items, 1) - } + require.NoError(t, err) + assert.Len(t, cronWfs.Items, 1) }) t.Run("GetCronWorkflow", func(t *testing.T) { t.Run("Labelled", func(t *testing.T) { cronWf, err := server.GetCronWorkflow(ctx, &cronworkflowpkg.GetCronWorkflowRequest{Namespace: "my-ns", Name: "my-name"}) - if assert.NoError(t, err) { - assert.NotNil(t, cronWf) - } + require.NoError(t, err) + assert.NotNil(t, cronWf) }) t.Run("Unlabelled", func(t *testing.T) { _, err := server.GetCronWorkflow(ctx, &cronworkflowpkg.GetCronWorkflowRequest{Namespace: "my-ns", Name: "unlabelled"}) - assert.Error(t, err) + require.Error(t, err) }) }) t.Run("UpdateCronWorkflow", func(t *testing.T) { @@ -99,27 +96,26 @@ metadata: x := cronWf.DeepCopy() x.Spec.Schedule = "invalid" _, err := server.UpdateCronWorkflow(ctx, &cronworkflowpkg.UpdateCronWorkflowRequest{Namespace: "my-ns", CronWorkflow: x}) - assert.Error(t, err) + require.Error(t, err) }) t.Run("Labelled", func(t *testing.T) { cronWf, err := server.UpdateCronWorkflow(ctx, &cronworkflowpkg.UpdateCronWorkflowRequest{Namespace: "my-ns", CronWorkflow: &cronWf}) - if assert.NoError(t, err) { - assert.NotNil(t, cronWf) - } + require.NoError(t, err) + assert.NotNil(t, cronWf) }) t.Run("Unlabelled", func(t *testing.T) { _, err := server.UpdateCronWorkflow(ctx, &cronworkflowpkg.UpdateCronWorkflowRequest{Namespace: "my-ns", CronWorkflow: &unlabelled}) - assert.Error(t, err) + require.Error(t, err) }) }) t.Run("DeleteCronWorkflow", func(t *testing.T) { t.Run("Labelled", func(t *testing.T) { _, err := server.DeleteCronWorkflow(ctx, &cronworkflowpkg.DeleteCronWorkflowRequest{Name: "my-name", Namespace: "my-ns"}) - assert.NoError(t, err) + require.NoError(t, err) }) t.Run("Unlabelled", func(t *testing.T) { _, err := server.DeleteCronWorkflow(ctx, &cronworkflowpkg.DeleteCronWorkflowRequest{Name: "unlabelled", Namespace: "my-ns"}) - assert.Error(t, err) + require.Error(t, err) }) }) } diff --git a/server/event/dispatch/operation_test.go b/server/event/dispatch/operation_test.go index 80cb11749cdf..e99508577fb8 100644 --- a/server/event/dispatch/operation_test.go +++ b/server/event/dispatch/operation_test.go @@ -9,6 +9,7 @@ import ( "github.com/go-jose/go-jose/v3/jwt" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "google.golang.org/grpc/metadata" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/tools/record" @@ -163,9 +164,9 @@ func TestNewOperation(t *testing.T) { }, }, }, "my-ns", "my-discriminator", &wfv1.Item{Value: json.RawMessage(`{"foo": {"bar": "baz"}, "formatted": "My%Test%"}`)}) - assert.NoError(t, err) + require.NoError(t, err) err = operation.Dispatch(ctx) - assert.Error(t, err) + require.Error(t, err) expectedParamValues := []string{ `My%Test%`, @@ -176,7 +177,8 @@ func TestNewOperation(t *testing.T) { var paramValues []string // assert list, err := client.ArgoprojV1alpha1().Workflows("my-ns").List(ctx, metav1.ListOptions{}) - if assert.NoError(t, err) && assert.Len(t, list.Items, 4) { + require.NoError(t, err) + if assert.Len(t, list.Items, 4) { for _, wf := range list.Items { assert.Equal(t, "my-instanceid", wf.Labels[common.LabelKeyControllerInstanceID]) assert.Equal(t, "my-sub", wf.Labels[common.LabelKeyCreator]) @@ -352,13 +354,13 @@ func Test_populateWorkflowMetadata(t *testing.T) { }, "my-ns", "my-discriminator", &wfv1.Item{Value: json.RawMessage(`{"foo": {"bar": "baz", "numeric": 8675309, "bool": true, "pr": 112}, "list": ["one", "two"]}`)}) - assert.NoError(t, err) + require.NoError(t, err) err = operation.Dispatch(ctx) - assert.Error(t, err) + require.Error(t, err) list, err := client.ArgoprojV1alpha1().Workflows("my-ns").List(ctx, metav1.ListOptions{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, list.Items, 4) expectedNames := []string{ @@ -405,10 +407,9 @@ func Test_populateWorkflowMetadata(t *testing.T) { func Test_expressionEnvironment(t *testing.T) { env, err := expressionEnvironment(context.TODO(), "my-ns", "my-d", &wfv1.Item{Value: []byte(`{"foo":"bar"}`)}) - if assert.NoError(t, err) { - assert.Equal(t, "my-ns", env["namespace"]) - assert.Equal(t, "my-d", env["discriminator"]) - assert.Contains(t, env, "metadata") - assert.Equal(t, map[string]interface{}{"foo": "bar"}, env["payload"], "make sure we parse an object as a map") - } + require.NoError(t, err) + assert.Equal(t, "my-ns", env["namespace"]) + assert.Equal(t, "my-d", env["discriminator"]) + assert.Contains(t, env, "metadata") + assert.Equal(t, map[string]interface{}{"foo": "bar"}, env["payload"], "make sure we parse an object as a map") } diff --git a/server/event/event_server_test.go b/server/event/event_server_test.go index 49f5c7003a92..2dd7961872e6 100644 --- a/server/event/event_server_test.go +++ b/server/event/event_server_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" fakekube "k8s.io/client-go/kubernetes/fake" eventpkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/event" @@ -30,12 +31,12 @@ func TestController(t *testing.T) { s := newController(true) _, err := s.ReceiveEvent(ctx, e1) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, s.operationQueue, 1, "one event to be processed") _, err = s.ReceiveEvent(ctx, e2) - assert.EqualError(t, err, "rpc error: code = Unavailable desc = operation queue full", "backpressure when queue is full") + require.EqualError(t, err, "rpc error: code = Unavailable desc = operation queue full", "backpressure when queue is full") stopCh := make(chan struct{}, 1) stopCh <- struct{}{} @@ -47,14 +48,14 @@ func TestController(t *testing.T) { s := newController(false) _, err := s.ReceiveEvent(ctx, e1) - assert.NoError(t, err) + require.NoError(t, err) _, err = s.ReceiveEvent(ctx, e2) - assert.NoError(t, err) + require.NoError(t, err) }) t.Run("SyncError", func(t *testing.T) { s := newController(false) _, err := s.ReceiveEvent(ctx, &eventpkg.EventRequest{Namespace: "my-ns", Payload: &wfv1.Item{Value: json.RawMessage("!")}}) - assert.EqualError(t, err, "rpc error: code = Internal desc = failed to create workflow template expression environment: json: error calling MarshalJSON for type *v1alpha1.Item: invalid character '!' looking for beginning of value") + require.EqualError(t, err, "rpc error: code = Internal desc = failed to create workflow template expression environment: json: error calling MarshalJSON for type *v1alpha1.Item: invalid character '!' looking for beginning of value") }) } diff --git a/server/info/info_server_test.go b/server/info/info_server_test.go index 4bbc03edff4c..5b747223ef89 100644 --- a/server/info/info_server_test.go +++ b/server/info/info_server_test.go @@ -6,6 +6,7 @@ import ( "github.com/go-jose/go-jose/v3/jwt" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" wfv1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1" "github.com/argoproj/argo-workflows/v3/server/auth" @@ -16,15 +17,14 @@ func Test_infoServer_GetUserInfo(t *testing.T) { i := &infoServer{} ctx := context.WithValue(context.TODO(), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Issuer: "my-iss", Subject: "my-sub"}, Groups: []string{"my-group"}, Name: "myname", Email: "my@email", EmailVerified: true, ServiceAccountName: "my-sa"}) info, err := i.GetUserInfo(ctx, nil) - if assert.NoError(t, err) { - assert.Equal(t, "my-iss", info.Issuer) - assert.Equal(t, "my-sub", info.Subject) - assert.Equal(t, []string{"my-group"}, info.Groups) - assert.Equal(t, "myname", info.Name) - assert.Equal(t, "my@email", info.Email) - assert.True(t, info.EmailVerified) - assert.Equal(t, "my-sa", info.ServiceAccountName) - } + require.NoError(t, err) + assert.Equal(t, "my-iss", info.Issuer) + assert.Equal(t, "my-sub", info.Subject) + assert.Equal(t, []string{"my-group"}, info.Groups) + assert.Equal(t, "myname", info.Name) + assert.Equal(t, "my@email", info.Email) + assert.True(t, info.EmailVerified) + assert.Equal(t, "my-sa", info.ServiceAccountName) } func Test_infoServer_GetInfo(t *testing.T) { @@ -40,24 +40,22 @@ func Test_infoServer_GetInfo(t *testing.T) { navColor: "red", } info, err := i.GetInfo(context.TODO(), nil) - if assert.NoError(t, err) { - assert.Equal(t, "argo", info.ManagedNamespace) - assert.Equal(t, "link-name", info.Links[0].Name) - assert.Equal(t, "red", info.NavColor) - assert.Equal(t, "Workflow Completed", info.Columns[0].Name) - assert.Equal(t, "label", info.Columns[0].Type) - assert.Equal(t, "workflows.argoproj.io/completed", info.Columns[0].Key) - } + require.NoError(t, err) + assert.Equal(t, "argo", info.ManagedNamespace) + assert.Equal(t, "link-name", info.Links[0].Name) + assert.Equal(t, "red", info.NavColor) + assert.Equal(t, "Workflow Completed", info.Columns[0].Name) + assert.Equal(t, "label", info.Columns[0].Type) + assert.Equal(t, "workflows.argoproj.io/completed", info.Columns[0].Key) }) t.Run("Min Fields", func(t *testing.T) { i := &infoServer{} info, err := i.GetInfo(context.TODO(), nil) - if assert.NoError(t, err) { - assert.Equal(t, "", info.ManagedNamespace) - assert.Empty(t, info.Links) - assert.Empty(t, info.Columns) - assert.Equal(t, "", info.NavColor) - } + require.NoError(t, err) + assert.Equal(t, "", info.ManagedNamespace) + assert.Empty(t, info.Links) + assert.Empty(t, info.Columns) + assert.Equal(t, "", info.NavColor) }) } diff --git a/server/sensor/sensor_server_test.go b/server/sensor/sensor_server_test.go index 223b7fb7587c..2175c04bd014 100644 --- a/server/sensor/sensor_server_test.go +++ b/server/sensor/sensor_server_test.go @@ -9,6 +9,7 @@ import ( "github.com/argoproj/argo-events/pkg/client/sensor/clientset/versioned/typed/sensor/v1alpha1" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" sensorpkg "github.com/argoproj/argo-workflows/v3/pkg/apiclient/sensor" @@ -67,7 +68,7 @@ func TestListSensors(t *testing.T) { sensorList, err := server.ListSensors(ctx, request) - assert.EqualError(t, err, "sensor client is not set", "Expected no error") + require.EqualError(t, err, "sensor client is not set", "Expected no error") assert.Nil(t, sensorList, "Expected sensor list to be nil") assert.NotNil(t, mockClient, "Expected mock client to be not nil") assert.Contains(t, err.Error(), "sensor client", "Expected error message to mention sensor client") @@ -94,7 +95,7 @@ func TestListSensors_SensorClientNotSet(t *testing.T) { sensorList, err := server.ListSensors(ctx, request) - assert.Error(t, err, "Expected error") + require.Error(t, err, "Expected error") assert.Nil(t, sensorList, "Expected sensor list to be nil") assert.Equal(t, "sensor client is not set", err.Error(), "Expected error message to match") } diff --git a/server/utils/errors_test.go b/server/utils/errors_test.go index 885c004054fb..2b565c171256 100644 --- a/server/utils/errors_test.go +++ b/server/utils/errors_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -62,7 +63,7 @@ func TestRecursiveStatus(t *testing.T) { func TestNilStatus(t *testing.T) { newErr := ToStatusError(nil, codes.InvalidArgument) - assert.NoError(t, newErr) + require.NoError(t, newErr) } func TestArgoError(t *testing.T) { diff --git a/server/workflow/store/sqlite_store_test.go b/server/workflow/store/sqlite_store_test.go index 086c755014a7..e79477aa4d0b 100644 --- a/server/workflow/store/sqlite_store_test.go +++ b/server/workflow/store/sqlite_store_test.go @@ -19,7 +19,7 @@ import ( func TestInitDB(t *testing.T) { conn, err := initDB() - assert.NoError(t, err) + require.NoError(t, err) defer conn.Close() t.Run("TestTablesCreated", func(t *testing.T) { err = sqlitex.Execute(conn, `select name from sqlite_master where type='table'`, &sqlitex.ExecOptions{ diff --git a/server/workflow/workflow_server_test.go b/server/workflow/workflow_server_test.go index aa6276ccac31..a6a6d110a315 100644 --- a/server/workflow/workflow_server_test.go +++ b/server/workflow/workflow_server_test.go @@ -9,6 +9,7 @@ import ( "github.com/go-jose/go-jose/v3/jwt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" authorizationv1 "k8s.io/api/authorization/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -141,11 +142,11 @@ const wf2 = ` "uid": "91066a6c-1ddc-11ea-b443-42010aa80074" }, "spec": { - + "entrypoint": "whalesay", "templates": [ { - + "container": { "args": [ "hello world" @@ -204,11 +205,11 @@ const wf3 = ` "uid": "6522aff1-1e01-11ea-b443-42010aa80074" }, "spec": { - + "entrypoint": "whalesay", "templates": [ { - + "container": { "args": [ "hello world" @@ -267,11 +268,11 @@ const wf4 = ` "uid": "91066a6c-1ddc-11ea-b443-42010aa80075" }, "spec": { - + "entrypoint": "whalesay", "templates": [ { - + "container": { "args": [ "hello world" @@ -330,11 +331,11 @@ const wf5 = ` "uid": "6522aff1-1e01-11ea-b443-42010aa80073" }, "spec": { - + "entrypoint": "whalesay", "templates": [ { - + "container": { "args": [ "hello world" @@ -666,11 +667,10 @@ func TestCreateWorkflow(t *testing.T) { var req workflowpkg.WorkflowCreateRequest v1alpha1.MustUnmarshal(workflow1, &req) wf, err := server.CreateWorkflow(ctx, &req) - if assert.NoError(t, err) { - assert.NotNil(t, wf) - assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID) - assert.Contains(t, wf.Labels, common.LabelKeyCreator) - } + require.NoError(t, err) + assert.NotNil(t, wf) + assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID) + assert.Contains(t, wf.Labels, common.LabelKeyCreator) } type testWatchWorkflowServer struct { @@ -690,7 +690,7 @@ func TestWatchWorkflows(t *testing.T) { ctx, cancel := context.WithCancel(ctx) go func() { err := server.WatchWorkflows(&workflowpkg.WatchWorkflowsRequest{}, &testWatchWorkflowServer{testServerStream{ctx}}) - assert.NoError(t, err) + require.NoError(t, err) }() cancel() } @@ -708,7 +708,7 @@ func TestWatchLatestWorkflow(t *testing.T) { FieldSelector: util.GenerateFieldSelectorFromWorkflowName("@latest"), }, }, &testWatchWorkflowServer{testServerStream{ctx}}) - assert.NoError(t, err) + require.NoError(t, err) }() cancel() } @@ -717,13 +717,12 @@ func TestGetWorkflowWithNotFound(t *testing.T) { server, ctx := getWorkflowServer() t.Run("Labelled", func(t *testing.T) { wf, err := getWorkflow(ctx, server, "test", "not-found") - if assert.Error(t, err) { - assert.Nil(t, wf) - } + require.Error(t, err) + assert.Nil(t, wf) }) t.Run("Unlabelled", func(t *testing.T) { _, err := getWorkflow(ctx, server, "test", "unlabelled") - assert.Error(t, err) + require.Error(t, err) }) } @@ -731,9 +730,8 @@ func TestGetLatestWorkflow(t *testing.T) { _, ctx := getWorkflowServer() wfClient := ctx.Value(auth.WfKey).(versioned.Interface) wf, err := getLatestWorkflow(ctx, wfClient, "test") - if assert.NoError(t, err) { - assert.Equal(t, "hello-world-9tql2-test", wf.Name) - } + require.NoError(t, err) + assert.Equal(t, "hello-world-9tql2-test", wf.Name) } func TestGetWorkflow(t *testing.T) { @@ -741,13 +739,11 @@ func TestGetWorkflow(t *testing.T) { s := server.(*workflowServer) wfClient := auth.GetWfClient(ctx) wf, err := s.getWorkflow(ctx, wfClient, "test", "hello-world-9tql2-test", metav1.GetOptions{}) - if assert.NoError(t, err) { - assert.NotNil(t, wf) - } + require.NoError(t, err) + assert.NotNil(t, wf) wf, err = s.getWorkflow(ctx, wfClient, "test", "hello-world-9tql2-test", metav1.GetOptions{}) - if assert.NoError(t, err) { - assert.NotNil(t, wf) - } + require.NoError(t, err) + assert.NotNil(t, wf) } func TestValidateWorkflow(t *testing.T) { @@ -755,40 +751,36 @@ func TestValidateWorkflow(t *testing.T) { s := server.(*workflowServer) wfClient := auth.GetWfClient(ctx) wf, err := s.getWorkflow(ctx, wfClient, "test", "hello-world-9tql2-test", metav1.GetOptions{}) - if assert.NoError(t, err) { - assert.NoError(t, s.validateWorkflow(wf)) - } + require.NoError(t, err) + require.NoError(t, s.validateWorkflow(wf)) } func TestListWorkflow(t *testing.T) { server, ctx := getWorkflowServer() wfl, err := getWorkflowList(ctx, server, "workflows") - if assert.NoError(t, err) { - assert.NotNil(t, wfl) - assert.Len(t, wfl.Items, 4) - } + require.NoError(t, err) + assert.NotNil(t, wfl) + assert.Len(t, wfl.Items, 4) wfl, err = getWorkflowList(ctx, server, "test") - if assert.NoError(t, err) { - assert.NotNil(t, wfl) - assert.Len(t, wfl.Items, 2) - } + require.NoError(t, err) + assert.NotNil(t, wfl) + assert.Len(t, wfl.Items, 2) } func TestDeleteWorkflow(t *testing.T) { server, ctx := getWorkflowServer() t.Run("Labelled", func(t *testing.T) { delRsp, err := server.DeleteWorkflow(ctx, &workflowpkg.WorkflowDeleteRequest{Name: "hello-world-b6h5m", Namespace: "workflows"}) - if assert.NoError(t, err) { - assert.NotNil(t, delRsp) - } + require.NoError(t, err) + assert.NotNil(t, delRsp) }) t.Run("Unlabelled", func(t *testing.T) { _, err := server.DeleteWorkflow(ctx, &workflowpkg.WorkflowDeleteRequest{Name: "unlabelled", Namespace: "workflows"}) - assert.Error(t, err) + require.Error(t, err) }) t.Run("Latest", func(t *testing.T) { _, err := server.DeleteWorkflow(ctx, &workflowpkg.WorkflowDeleteRequest{Name: "@latest", Namespace: "workflows"}) - assert.NoError(t, err) + require.NoError(t, err) }) } @@ -796,32 +788,29 @@ func TestRetryWorkflow(t *testing.T) { server, ctx := getWorkflowServer() t.Run("Labelled", func(t *testing.T) { retried, err := server.RetryWorkflow(ctx, &workflowpkg.WorkflowRetryRequest{Name: "failed", Namespace: "workflows"}) - if assert.NoError(t, err) { - assert.NotNil(t, retried) - } + require.NoError(t, err) + assert.NotNil(t, retried) }) t.Run("Unlabelled", func(t *testing.T) { _, err := server.RetryWorkflow(ctx, &workflowpkg.WorkflowRetryRequest{Name: "unlabelled", Namespace: "workflows"}) - assert.Error(t, err) + require.Error(t, err) }) t.Run("Latest", func(t *testing.T) { _, err := server.RetryWorkflow(ctx, &workflowpkg.WorkflowRetryRequest{Name: "latest", Namespace: "workflows"}) - assert.Error(t, err) + require.Error(t, err) }) } func TestSuspendResumeWorkflow(t *testing.T) { server, ctx := getWorkflowServer() wf, err := server.SuspendWorkflow(ctx, &workflowpkg.WorkflowSuspendRequest{Name: "hello-world-9tql2-run", Namespace: "workflows"}) - if assert.NoError(t, err) { - assert.NotNil(t, wf) - assert.True(t, *wf.Spec.Suspend) - wf, err = server.ResumeWorkflow(ctx, &workflowpkg.WorkflowResumeRequest{Name: wf.Name, Namespace: wf.Namespace}) - if assert.NoError(t, err) { - assert.NotNil(t, wf) - assert.Nil(t, wf.Spec.Suspend) - } - } + require.NoError(t, err) + assert.NotNil(t, wf) + assert.True(t, *wf.Spec.Suspend) + wf, err = server.ResumeWorkflow(ctx, &workflowpkg.WorkflowResumeRequest{Name: wf.Name, Namespace: wf.Namespace}) + require.NoError(t, err) + assert.NotNil(t, wf) + assert.Nil(t, wf.Spec.Suspend) } func TestSuspendResumeWorkflowWithNotFound(t *testing.T) { @@ -833,21 +822,21 @@ func TestSuspendResumeWorkflowWithNotFound(t *testing.T) { } wf, err := server.SuspendWorkflow(ctx, &susWfReq) assert.Nil(t, wf) - assert.Error(t, err) + require.Error(t, err) rsmWfReq := workflowpkg.WorkflowResumeRequest{ Name: "hello-world-9tql2-not", Namespace: "workflows", } wf, err = server.ResumeWorkflow(ctx, &rsmWfReq) assert.Nil(t, wf) - assert.Error(t, err) + require.Error(t, err) } func TestTerminateWorkflow(t *testing.T) { server, ctx := getWorkflowServer() wf, err := getWorkflow(ctx, server, "workflows", "hello-world-9tql2-run") - assert.NoError(t, err) + require.NoError(t, err) rsmWfReq := workflowpkg.WorkflowTerminateRequest{ Name: wf.Name, Namespace: wf.Namespace, @@ -855,7 +844,7 @@ func TestTerminateWorkflow(t *testing.T) { wf, err = server.TerminateWorkflow(ctx, &rsmWfReq) assert.NotNil(t, wf) assert.Equal(t, v1alpha1.ShutdownStrategyTerminate, wf.Spec.Shutdown) - assert.NoError(t, err) + require.NoError(t, err) rsmWfReq = workflowpkg.WorkflowTerminateRequest{ Name: "hello-world-9tql2-not", @@ -863,38 +852,35 @@ func TestTerminateWorkflow(t *testing.T) { } wf, err = server.TerminateWorkflow(ctx, &rsmWfReq) assert.Nil(t, wf) - assert.Error(t, err) + require.Error(t, err) } func TestStopWorkflow(t *testing.T) { server, ctx := getWorkflowServer() wf, err := getWorkflow(ctx, server, "workflows", "hello-world-9tql2-run") - assert.NoError(t, err) + require.NoError(t, err) rsmWfReq := workflowpkg.WorkflowStopRequest{Name: wf.Name, Namespace: wf.Namespace} wf, err = server.StopWorkflow(ctx, &rsmWfReq) - if assert.NoError(t, err) { - assert.NotNil(t, wf) - assert.Equal(t, v1alpha1.WorkflowRunning, wf.Status.Phase) - } + require.NoError(t, err) + assert.NotNil(t, wf) + assert.Equal(t, v1alpha1.WorkflowRunning, wf.Status.Phase) } func TestResubmitWorkflow(t *testing.T) { server, ctx := getWorkflowServer() t.Run("Labelled", func(t *testing.T) { wf, err := server.ResubmitWorkflow(ctx, &workflowpkg.WorkflowResubmitRequest{Name: "hello-world-9tql2", Namespace: "workflows"}) - if assert.NoError(t, err) { - assert.NotNil(t, wf) - } + require.NoError(t, err) + assert.NotNil(t, wf) }) t.Run("Unlabelled", func(t *testing.T) { _, err := server.ResubmitWorkflow(ctx, &workflowpkg.WorkflowResubmitRequest{Name: "unlabelled", Namespace: "workflows"}) - assert.Error(t, err) + require.Error(t, err) }) t.Run("Latest", func(t *testing.T) { wf, err := server.ResubmitWorkflow(ctx, &workflowpkg.WorkflowResubmitRequest{Name: "@latest", Namespace: "workflows"}) - if assert.NoError(t, err) { - assert.NotNil(t, wf) - } + require.NoError(t, err) + assert.NotNil(t, wf) }) } @@ -903,11 +889,10 @@ func TestLintWorkflow(t *testing.T) { wf := &v1alpha1.Workflow{} v1alpha1.MustUnmarshal(unlabelled, &wf) linted, err := server.LintWorkflow(ctx, &workflowpkg.WorkflowLintRequest{Workflow: wf}) - if assert.NoError(t, err) { - assert.NotNil(t, linted) - assert.Contains(t, linted.Labels, common.LabelKeyControllerInstanceID) - assert.Contains(t, linted.Labels, common.LabelKeyCreator) - } + require.NoError(t, err) + assert.NotNil(t, linted) + assert.Contains(t, linted.Labels, common.LabelKeyControllerInstanceID) + assert.Contains(t, linted.Labels, common.LabelKeyCreator) } type testPodLogsServer struct { @@ -927,7 +912,7 @@ func TestPodLogs(t *testing.T) { Namespace: "workflows", LogOptions: &corev1.PodLogOptions{}, }, &testPodLogsServer{testServerStream{ctx}}) - assert.NoError(t, err) + require.NoError(t, err) }() cancel() } @@ -940,7 +925,7 @@ func TestSubmitWorkflowFromResource(t *testing.T) { ResourceKind: "workflowtemplate", ResourceName: "workflow-template-whalesay-template", }) - assert.EqualError(t, err, "rpc error: code = InvalidArgument desc = spec.arguments.message.value or spec.arguments.message.valueFrom is required") + require.EqualError(t, err, "rpc error: code = InvalidArgument desc = spec.arguments.message.value or spec.arguments.message.valueFrom is required") }) t.Run("SubmitFromWorkflowTemplate", func(t *testing.T) { opts := v1alpha1.SubmitOpts{ @@ -954,11 +939,10 @@ func TestSubmitWorkflowFromResource(t *testing.T) { ResourceName: "workflow-template-whalesay-template", SubmitOptions: &opts, }) - if assert.NoError(t, err) { - assert.NotNil(t, wf) - assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID) - assert.Contains(t, wf.Labels, common.LabelKeyCreator) - } + require.NoError(t, err) + assert.NotNil(t, wf) + assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID) + assert.Contains(t, wf.Labels, common.LabelKeyCreator) }) t.Run("SubmitFromCronWorkflow", func(t *testing.T) { wf, err := server.SubmitWorkflow(ctx, &workflowpkg.WorkflowSubmitRequest{ @@ -966,11 +950,10 @@ func TestSubmitWorkflowFromResource(t *testing.T) { ResourceKind: "cronworkflow", ResourceName: "hello-world", }) - if assert.NoError(t, err) { - assert.NotNil(t, wf) - assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID) - assert.Contains(t, wf.Labels, common.LabelKeyCreator) - } + require.NoError(t, err) + assert.NotNil(t, wf) + assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID) + assert.Contains(t, wf.Labels, common.LabelKeyCreator) }) t.Run("SubmitFromClusterWorkflowTemplate", func(t *testing.T) { wf, err := server.SubmitWorkflow(ctx, &workflowpkg.WorkflowSubmitRequest{ @@ -978,10 +961,9 @@ func TestSubmitWorkflowFromResource(t *testing.T) { ResourceKind: "ClusterWorkflowTemplate", ResourceName: "cluster-workflow-template-whalesay-template", }) - if assert.NoError(t, err) { - assert.NotNil(t, wf) - assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID) - assert.Contains(t, wf.Labels, common.LabelKeyCreator) - } + require.NoError(t, err) + assert.NotNil(t, wf) + assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID) + assert.Contains(t, wf.Labels, common.LabelKeyCreator) }) } diff --git a/server/workflowarchive/archived_workflow_server_test.go b/server/workflowarchive/archived_workflow_server_test.go index 8feab2eaf47b..3f66a5919c09 100644 --- a/server/workflowarchive/archived_workflow_server_test.go +++ b/server/workflowarchive/archived_workflow_server_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" authorizationv1 "k8s.io/api/authorization/v1" @@ -135,62 +136,52 @@ func Test_archivedWorkflowServer(t *testing.T) { assert.Equal(t, err, status.Error(codes.PermissionDenied, "Permission denied, you are not allowed to list workflows in namespace \"\". Maybe you want to specify a namespace with query parameter `.namespace=`?")) allowed = true resp, err := w.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{ListOptions: &metav1.ListOptions{Limit: 1}}) - if assert.NoError(t, err) { - assert.Len(t, resp.Items, 1) - assert.Equal(t, "1", resp.Continue) - } + require.NoError(t, err) + assert.Len(t, resp.Items, 1) + assert.Equal(t, "1", resp.Continue) resp, err = w.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{ListOptions: &metav1.ListOptions{Continue: "1", Limit: 1}}) - if assert.NoError(t, err) { - assert.Len(t, resp.Items, 1) - assert.Empty(t, resp.Continue) - } + require.NoError(t, err) + assert.Len(t, resp.Items, 1) + assert.Empty(t, resp.Continue) resp, err = w.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{ListOptions: &metav1.ListOptions{FieldSelector: "spec.startedAt>2020-01-01T00:00:00Z,spec.startedAt<2020-01-02T00:00:00Z", Limit: 1}}) - if assert.NoError(t, err) { - assert.Len(t, resp.Items, 1) - assert.Empty(t, resp.Continue) - } + require.NoError(t, err) + assert.Len(t, resp.Items, 1) + assert.Empty(t, resp.Continue) resp, err = w.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{ListOptions: &metav1.ListOptions{FieldSelector: "metadata.name=my-name,spec.startedAt>2020-01-01T00:00:00Z,spec.startedAt<2020-01-02T00:00:00Z", Limit: 1}}) - if assert.NoError(t, err) { - assert.Len(t, resp.Items, 1) - assert.Empty(t, resp.Continue) - } + require.NoError(t, err) + assert.Len(t, resp.Items, 1) + assert.Empty(t, resp.Continue) resp, err = w.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{ListOptions: &metav1.ListOptions{FieldSelector: "spec.startedAt>2020-01-01T00:00:00Z,spec.startedAt<2020-01-02T00:00:00Z", Limit: 1}, NamePrefix: "my-"}) - if assert.NoError(t, err) { - assert.Len(t, resp.Items, 1) - assert.Empty(t, resp.Continue) - } + require.NoError(t, err) + assert.Len(t, resp.Items, 1) + assert.Empty(t, resp.Continue) resp, err = w.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{ListOptions: &metav1.ListOptions{FieldSelector: "metadata.name=my-name,spec.startedAt>2020-01-01T00:00:00Z,spec.startedAt<2020-01-02T00:00:00Z", Limit: 1}, NamePrefix: "my-"}) - if assert.NoError(t, err) { - assert.Len(t, resp.Items, 1) - assert.Empty(t, resp.Continue) - } + require.NoError(t, err) + assert.Len(t, resp.Items, 1) + assert.Empty(t, resp.Continue) resp, err = w.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{ListOptions: &metav1.ListOptions{FieldSelector: "metadata.name=my-name,spec.startedAt>2020-01-01T00:00:00Z,spec.startedAt<2020-01-02T00:00:00Z,ext.showRemainingItemCount=true", Limit: 1}, NamePrefix: "my-"}) - if assert.NoError(t, err) { - assert.Len(t, resp.Items, 1) - assert.Equal(t, int64(4), *resp.ListMeta.RemainingItemCount) - assert.Empty(t, resp.Continue) - } + require.NoError(t, err) + assert.Len(t, resp.Items, 1) + assert.Equal(t, int64(4), *resp.ListMeta.RemainingItemCount) + assert.Empty(t, resp.Continue) /////// Currently, for the purpose of backward compatibility, namespace is supported both as its own query parameter and as part of the field selector /////// need to test both // pass namespace as its own query parameter resp, err = w.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{Namespace: "user-ns", ListOptions: &metav1.ListOptions{Limit: 1}}) - if assert.NoError(t, err) { - assert.Len(t, resp.Items, 1) - assert.Equal(t, "1", resp.Continue) - } + require.NoError(t, err) + assert.Len(t, resp.Items, 1) + assert.Equal(t, "1", resp.Continue) // pass namespace as field selector and not query parameter resp, err = w.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{ListOptions: &metav1.ListOptions{Limit: 1, FieldSelector: "metadata.namespace=user-ns"}}) - if assert.NoError(t, err) { - assert.Len(t, resp.Items, 1) - assert.Equal(t, "1", resp.Continue) - } + require.NoError(t, err) + assert.Len(t, resp.Items, 1) + assert.Equal(t, "1", resp.Continue) // pass namespace as field selector and query parameter both, where both match resp, err = w.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{Namespace: "user-ns", ListOptions: &metav1.ListOptions{Limit: 1, FieldSelector: "metadata.namespace=user-ns"}}) - if assert.NoError(t, err) { - assert.Len(t, resp.Items, 1) - assert.Equal(t, "1", resp.Continue) - } + require.NoError(t, err) + assert.Len(t, resp.Items, 1) + assert.Equal(t, "1", resp.Continue) // pass namespace as field selector and query parameter both, where they don't match _, err = w.ListArchivedWorkflows(ctx, &workflowarchivepkg.ListArchivedWorkflowsRequest{Namespace: "user-ns", ListOptions: &metav1.ListOptions{Limit: 1, FieldSelector: "metadata.namespace=other-ns"}}) @@ -205,7 +196,7 @@ func Test_archivedWorkflowServer(t *testing.T) { _, err = w.GetArchivedWorkflow(ctx, &workflowarchivepkg.GetArchivedWorkflowRequest{}) assert.Equal(t, err, status.Error(codes.NotFound, "not found")) wf, err := w.GetArchivedWorkflow(ctx, &workflowarchivepkg.GetArchivedWorkflowRequest{Uid: "my-uid"}) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, wf) repo.On("GetWorkflow", "", "my-ns", "my-name").Return(&wfv1.Workflow{ @@ -218,7 +209,7 @@ func Test_archivedWorkflowServer(t *testing.T) { }, }, nil) wf, err = w.GetArchivedWorkflow(ctx, &workflowarchivepkg.GetArchivedWorkflowRequest{Uid: "", Name: "my-name", Namespace: "my-ns"}) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, wf) }) t.Run("DeleteArchivedWorkflow", func(t *testing.T) { @@ -227,16 +218,16 @@ func Test_archivedWorkflowServer(t *testing.T) { assert.Equal(t, err, status.Error(codes.PermissionDenied, "permission denied")) allowed = true _, err = w.DeleteArchivedWorkflow(ctx, &workflowarchivepkg.DeleteArchivedWorkflowRequest{Uid: "my-uid"}) - assert.NoError(t, err) + require.NoError(t, err) }) t.Run("ListArchivedWorkflowLabelKeys", func(t *testing.T) { resp, err := w.ListArchivedWorkflowLabelKeys(ctx, &workflowarchivepkg.ListArchivedWorkflowLabelKeysRequest{}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, resp.Items, 2) }) t.Run("ListArchivedWorkflowLabelValues", func(t *testing.T) { resp, err := w.ListArchivedWorkflowLabelValues(ctx, &workflowarchivepkg.ListArchivedWorkflowLabelValuesRequest{ListOptions: &metav1.ListOptions{LabelSelector: "my-key"}}) - assert.NoError(t, err) + require.NoError(t, err) assert.Len(t, resp.Items, 2) assert.False(t, matchLabelKeyPattern("my-key")) @@ -244,7 +235,7 @@ func Test_archivedWorkflowServer(t *testing.T) { 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) + require.NoError(t, err) assert.Empty(t, resp.Items) }) t.Run("RetryArchivedWorkflow", func(t *testing.T) { @@ -253,7 +244,7 @@ func Test_archivedWorkflowServer(t *testing.T) { }) t.Run("ResubmitArchivedWorkflow", func(t *testing.T) { wf, err := w.ResubmitArchivedWorkflow(ctx, &workflowarchivepkg.ResubmitArchivedWorkflowRequest{Uid: "resubmit-uid", Memoized: false}) - assert.NoError(t, err) + require.NoError(t, err) assert.NotNil(t, wf) }) } diff --git a/server/workflowtemplate/workflow_template_server_test.go b/server/workflowtemplate/workflow_template_server_test.go index 632784de9a11..35cf8ebd05f4 100644 --- a/server/workflowtemplate/workflow_template_server_test.go +++ b/server/workflowtemplate/workflow_template_server_test.go @@ -6,6 +6,7 @@ import ( "github.com/go-jose/go-jose/v3/jwt" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/fake" @@ -179,19 +180,17 @@ func TestWorkflowTemplateServer_CreateWorkflowTemplate(t *testing.T) { wftReq.Template.Name = "foo-without-param-values" wftReq.Template.Spec.Arguments.Parameters[0].Value = nil wftRsp, err := server.CreateWorkflowTemplate(ctx, &wftReq) - if assert.NoError(t, err) { - assert.NotNil(t, wftRsp) - assert.Equal(t, "message", wftRsp.Spec.Arguments.Parameters[0].Name) - assert.Nil(t, wftRsp.Spec.Arguments.Parameters[0].Value) - } + require.NoError(t, err) + assert.NotNil(t, wftRsp) + assert.Equal(t, "message", wftRsp.Spec.Arguments.Parameters[0].Name) + assert.Nil(t, wftRsp.Spec.Arguments.Parameters[0].Value) }) t.Run("Labelled", func(t *testing.T) { var wftReq workflowtemplatepkg.WorkflowTemplateCreateRequest v1alpha1.MustUnmarshal(wftStr1, &wftReq) wftRsp, err := server.CreateWorkflowTemplate(ctx, &wftReq) - if assert.NoError(t, err) { - assert.NotNil(t, wftRsp) - } + require.NoError(t, err) + assert.NotNil(t, wftRsp) }) t.Run("Unlabelled", func(t *testing.T) { var wftReq workflowtemplatepkg.WorkflowTemplateCreateRequest @@ -199,11 +198,10 @@ func TestWorkflowTemplateServer_CreateWorkflowTemplate(t *testing.T) { wftReq.Namespace = "default" wftReq.Template.Name = "foo" wftRsp, err := server.CreateWorkflowTemplate(ctx, &wftReq) - if assert.NoError(t, err) { - assert.NotNil(t, wftRsp) - assert.Contains(t, wftRsp.Labels, common.LabelKeyControllerInstanceID) - assert.Contains(t, wftRsp.Labels, common.LabelKeyCreator) - } + require.NoError(t, err) + assert.NotNil(t, wftRsp) + assert.Contains(t, wftRsp.Labels, common.LabelKeyControllerInstanceID) + assert.Contains(t, wftRsp.Labels, common.LabelKeyCreator) }) } @@ -211,40 +209,37 @@ func TestWorkflowTemplateServer_GetWorkflowTemplate(t *testing.T) { server, ctx := getWorkflowTemplateServer() t.Run("Labelled", func(t *testing.T) { wftRsp, err := server.GetWorkflowTemplate(ctx, &workflowtemplatepkg.WorkflowTemplateGetRequest{Name: "workflow-template-whalesay-template2", Namespace: "default"}) - if assert.NoError(t, err) { - assert.NotNil(t, wftRsp) - assert.Equal(t, "workflow-template-whalesay-template2", wftRsp.Name) - assert.Equal(t, "message", wftRsp.Spec.Arguments.Parameters[0].Name) - assert.Equal(t, "message description", wftRsp.Spec.Arguments.Parameters[0].Description.String()) - } + require.NoError(t, err) + assert.NotNil(t, wftRsp) + assert.Equal(t, "workflow-template-whalesay-template2", wftRsp.Name) + assert.Equal(t, "message", wftRsp.Spec.Arguments.Parameters[0].Name) + assert.Equal(t, "message description", wftRsp.Spec.Arguments.Parameters[0].Description.String()) }) t.Run("Unlabelled", func(t *testing.T) { _, err := server.GetWorkflowTemplate(ctx, &workflowtemplatepkg.WorkflowTemplateGetRequest{Name: "unlabelled", Namespace: "default"}) - assert.Error(t, err) + require.Error(t, err) }) } func TestWorkflowTemplateServer_ListWorkflowTemplates(t *testing.T) { server, ctx := getWorkflowTemplateServer() wftRsp, err := server.ListWorkflowTemplates(ctx, &workflowtemplatepkg.WorkflowTemplateListRequest{Namespace: "default"}) - if assert.NoError(t, err) { - assert.Len(t, wftRsp.Items, 2) - } + require.NoError(t, err) + assert.Len(t, wftRsp.Items, 2) wftRsp, err = server.ListWorkflowTemplates(ctx, &workflowtemplatepkg.WorkflowTemplateListRequest{Namespace: "test"}) - if assert.NoError(t, err) { - assert.Empty(t, wftRsp.Items) - } + require.NoError(t, err) + assert.Empty(t, wftRsp.Items) } func TestWorkflowTemplateServer_DeleteWorkflowTemplate(t *testing.T) { server, ctx := getWorkflowTemplateServer() t.Run("Labelled", func(t *testing.T) { _, err := server.DeleteWorkflowTemplate(ctx, &workflowtemplatepkg.WorkflowTemplateDeleteRequest{Namespace: "default", Name: "workflow-template-whalesay-template2"}) - assert.NoError(t, err) + require.NoError(t, err) }) t.Run("Unlabelled", func(t *testing.T) { _, err := server.DeleteWorkflowTemplate(ctx, &workflowtemplatepkg.WorkflowTemplateDeleteRequest{Namespace: "default", Name: "unlabelled"}) - assert.Error(t, err) + require.Error(t, err) }) } @@ -253,9 +248,8 @@ func TestWorkflowTemplateServer_LintWorkflowTemplate(t *testing.T) { tmpl, err := server.LintWorkflowTemplate(ctx, &workflowtemplatepkg.WorkflowTemplateLintRequest{ Template: &v1alpha1.WorkflowTemplate{}, }) - if assert.NoError(t, err) { - assert.Contains(t, tmpl.Labels, common.LabelKeyControllerInstanceID) - } + require.NoError(t, err) + assert.Contains(t, tmpl.Labels, common.LabelKeyControllerInstanceID) } func TestWorkflowTemplateServer_UpdateWorkflowTemplate(t *testing.T) { @@ -268,9 +262,8 @@ func TestWorkflowTemplateServer_UpdateWorkflowTemplate(t *testing.T) { Namespace: "default", Template: &wftObj1, }) - if assert.NoError(t, err) { - assert.Equal(t, "alpine:latest", wftRsp.Spec.Templates[0].Container.Image) - } + require.NoError(t, err) + assert.Equal(t, "alpine:latest", wftRsp.Spec.Templates[0].Container.Image) }) t.Run("Unlabelled", func(t *testing.T) { _, err := server.UpdateWorkflowTemplate(ctx, &workflowtemplatepkg.WorkflowTemplateUpdateRequest{ @@ -278,6 +271,6 @@ func TestWorkflowTemplateServer_UpdateWorkflowTemplate(t *testing.T) { ObjectMeta: metav1.ObjectMeta{Name: "unlabelled"}, }, }) - assert.Error(t, err) + require.Error(t, err) }) } diff --git a/test/e2e/argo_server_test.go b/test/e2e/argo_server_test.go index 8b0a53af1e5b..fc7d6e99b298 100644 --- a/test/e2e/argo_server_test.go +++ b/test/e2e/argo_server_test.go @@ -132,7 +132,7 @@ func (s *ArgoServerSuite) TestSubmitWorkflowTemplateFromGithubWebhook() { s.bearerToken = "" data, err := os.ReadFile("testdata/github-webhook-payload.json") - s.NoError(err) + s.Require().NoError(err) s.Given(). WorkflowTemplate(` @@ -380,9 +380,9 @@ func (s *ArgoServerSuite) TestMultiCookieAuth() { func (s *ArgoServerSuite) createServiceAccount(name string) { ctx := context.Background() _, err := s.KubeClient.CoreV1().ServiceAccounts(fixtures.Namespace).Create(ctx, &corev1.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: name}}, metav1.CreateOptions{}) - s.NoError(err) + s.Require().NoError(err) secret, err := s.KubeClient.CoreV1().Secrets(fixtures.Namespace).Create(ctx, secrets.NewTokenSecret(name), metav1.CreateOptions{}) - s.NoError(err) + s.Require().NoError(err) s.T().Cleanup(func() { _ = s.KubeClient.CoreV1().Secrets(fixtures.Namespace).Delete(ctx, secret.Name, metav1.DeleteOptions{}) _ = s.KubeClient.CoreV1().ServiceAccounts(fixtures.Namespace).Delete(ctx, name, metav1.DeleteOptions{}) @@ -401,11 +401,11 @@ func (s *ArgoServerSuite) TestPermission() { var roleName string s.Run("LoadRoleYaml", func() { obj, err := fixtures.LoadObject("@testdata/argo-server-test-role.yaml") - s.NoError(err) + s.Require().NoError(err) role, _ := obj.(*rbacv1.Role) roleName = role.Name _, err = s.KubeClient.RbacV1().Roles(nsName).Create(ctx, role, metav1.CreateOptions{}) - s.NoError(err) + s.Require().NoError(err) }) defer func() { _ = s.KubeClient.RbacV1().Roles(nsName).Delete(ctx, roleName, metav1.DeleteOptions{}) @@ -424,7 +424,7 @@ func (s *ArgoServerSuite) TestPermission() { } s.Run("CreateRoleBinding", func() { _, err := s.KubeClient.RbacV1().RoleBindings(nsName).Create(ctx, roleBinding, metav1.CreateOptions{}) - s.NoError(err) + s.Require().NoError(err) }) defer func() { _ = s.KubeClient.RbacV1().RoleBindings(nsName).Delete(ctx, roleBindingName, metav1.DeleteOptions{}) @@ -438,22 +438,21 @@ func (s *ArgoServerSuite) TestPermission() { var goodToken string s.Run("GetGoodSAToken", func() { sAccount, err := s.KubeClient.CoreV1().ServiceAccounts(nsName).Get(ctx, goodSaName, metav1.GetOptions{}) - if s.NoError(err) { - secretName := secrets.TokenNameForServiceAccount(sAccount) - secret, err := s.KubeClient.CoreV1().Secrets(nsName).Get(ctx, secretName, metav1.GetOptions{}) - s.NoError(err) - goodToken = string(secret.Data["token"]) - } + s.Require().NoError(err) + secretName := secrets.TokenNameForServiceAccount(sAccount) + secret, err := s.KubeClient.CoreV1().Secrets(nsName).Get(ctx, secretName, metav1.GetOptions{}) + s.Require().NoError(err) + goodToken = string(secret.Data["token"]) }) // Get token of bad serviceaccount var badToken string s.Run("GetBadSAToken", func() { sAccount, err := s.KubeClient.CoreV1().ServiceAccounts(nsName).Get(ctx, badSaName, metav1.GetOptions{}) - s.NoError(err) + s.Require().NoError(err) secretName := secrets.TokenNameForServiceAccount(sAccount) secret, err := s.KubeClient.CoreV1().Secrets(nsName).Get(ctx, secretName, metav1.GetOptions{}) - s.NoError(err) + s.Require().NoError(err) badToken = string(secret.Data["token"]) }) @@ -752,7 +751,7 @@ func (s *ArgoServerSuite) TestWorkflowService() { "name": "run-workflow", "container": { "image": "argoproj/argosay:v2", - "args": ["sleep", "10s"] + "args": ["sleep", "10s"] } } ], @@ -1222,12 +1221,12 @@ func (s *ArgoServerSuite) artifactServerRetrievalTests(name string, uid types.UI func (s *ArgoServerSuite) stream(url string, f func(t *testing.T, line string) (done bool)) { t := s.T() req, err := http.NewRequest("GET", baseUrl+url, nil) - assert.NoError(t, err) + s.Require().NoError(err) req.Header.Set("Accept", "text/event-stream") req.Header.Set("Authorization", "Bearer "+s.bearerToken) req.Close = true resp, err := httpClient.Do(req) - assert.NoError(t, err) + s.Require().NoError(err) defer func() { if resp != nil && resp.Body != nil { _ = resp.Body.Close() @@ -1834,7 +1833,7 @@ func (s *ArgoServerSuite) TestEventSourcesService() { { "eventsource": { "metadata": { - "name": "test-event-source", + "name": "test-event-source", "labels": { "workflows.argoproj.io/test": "true" } @@ -1897,7 +1896,7 @@ func (s *ArgoServerSuite) TestEventSourcesService() { { "eventsource": { "metadata": { - "name": "test-event-source", + "name": "test-event-source", "resourceVersion": "` + resourceVersion + `", "labels": { "workflows.argoproj.io/test": "true" diff --git a/test/e2e/artifacts_test.go b/test/e2e/artifacts_test.go index ee3d89c307f9..9e894ce4e107 100644 --- a/test/e2e/artifacts_test.go +++ b/test/e2e/artifacts_test.go @@ -10,6 +10,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -185,18 +186,18 @@ func (s *ArtifactsSuite) TestStoppedWorkflow() { c, err := minio.New("localhost:9000", &minio.Options{ Creds: credentials.NewStaticV4("admin", "password", ""), }) - s.NoError(err) + s.Require().NoError(err) // Ensure the artifacts aren't in the bucket. _, err = c.StatObject(context.Background(), "my-bucket-3", "on-deletion-wf-stopped-1", minio.StatObjectOptions{}) if err == nil { err = c.RemoveObject(context.Background(), "my-bucket-3", "on-deletion-wf-stopped-1", minio.RemoveObjectOptions{}) - s.NoError(err) + s.Require().NoError(err) } _, err = c.StatObject(context.Background(), "my-bucket-3", "on-deletion-wf-stopped-2", minio.StatObjectOptions{}) if err == nil { err = c.RemoveObject(context.Background(), "my-bucket-3", "on-deletion-wf-stopped-2", minio.RemoveObjectOptions{}) - s.NoError(err) + s.Require().NoError(err) } then := s.Given(). @@ -206,10 +207,10 @@ func (s *ArtifactsSuite) TestStoppedWorkflow() { // Assert the artifacts don't exist. then.ExpectArtifactByKey("on-deletion-wf-stopped-1", "my-bucket-3", func(t *testing.T, object minio.ObjectInfo, err error) { - assert.Error(t, err) + require.Error(t, err) }) then.ExpectArtifactByKey("on-deletion-wf-stopped-2", "my-bucket-3", func(t *testing.T, object minio.ObjectInfo, err error) { - assert.Error(t, err) + require.Error(t, err) }) when := then.When(). @@ -234,10 +235,10 @@ func (s *ArtifactsSuite) TestStoppedWorkflow() { // Assert artifact exists then.ExpectArtifactByKey("on-deletion-wf-stopped-1", "my-bucket-3", func(t *testing.T, object minio.ObjectInfo, err error) { - assert.NoError(t, err) + require.NoError(t, err) }) then.ExpectArtifactByKey("on-deletion-wf-stopped-2", "my-bucket-3", func(t *testing.T, object minio.ObjectInfo, err error) { - assert.NoError(t, err) + require.NoError(t, err) }) when = then.When() @@ -250,10 +251,10 @@ func (s *ArtifactsSuite) TestStoppedWorkflow() { // Assert the artifacts don't exist. then.ExpectArtifactByKey("on-deletion-wf-stopped-1", "my-bucket-3", func(t *testing.T, object minio.ObjectInfo, err error) { - assert.Error(t, err) + require.Error(t, err) }) then.ExpectArtifactByKey("on-deletion-wf-stopped-2", "my-bucket-3", func(t *testing.T, object minio.ObjectInfo, err error) { - assert.Error(t, err) + require.Error(t, err) }) when = then.When() @@ -438,12 +439,12 @@ func (s *ArtifactsSuite) TestArtifactGC() { if expectedArtifact.deletedAtWFCompletion { fmt.Printf("verifying artifact %s is deleted at completion time\n", artifactKey) then.ExpectArtifactByKey(artifactKey, expectedArtifact.artifactLocation.bucketName, func(t *testing.T, object minio.ObjectInfo, err error) { - assert.Error(t, err) + require.Error(t, err) }) } else { fmt.Printf("verifying artifact %s is not deleted at completion time\n", artifactKey) then.ExpectArtifactByKey(artifactKey, expectedArtifact.artifactLocation.bucketName, func(t *testing.T, object minio.ObjectInfo, err error) { - assert.NoError(t, err) + require.NoError(t, err) }) } } @@ -473,12 +474,12 @@ func (s *ArtifactsSuite) TestArtifactGC() { if expectedArtifact.deletedAtWFDeletion { fmt.Printf("verifying artifact %s is deleted\n", artifactKey) then.ExpectArtifactByKey(artifactKey, expectedArtifact.artifactLocation.bucketName, func(t *testing.T, object minio.ObjectInfo, err error) { - assert.Error(t, err) + require.Error(t, err) }) } else { fmt.Printf("verifying artifact %s is not deleted\n", artifactKey) then.ExpectArtifactByKey(artifactKey, expectedArtifact.artifactLocation.bucketName, func(t *testing.T, object minio.ObjectInfo, err error) { - assert.NoError(t, err) + require.NoError(t, err) }) } } @@ -520,7 +521,7 @@ spec: func (s *ArtifactsSuite) TestInsufficientRole() { ctx := context.Background() _, err := s.KubeClient.CoreV1().ServiceAccounts(fixtures.Namespace).Create(ctx, &corev1.ServiceAccount{ObjectMeta: metav1.ObjectMeta{Name: "artgc-role-test-sa"}}, metav1.CreateOptions{}) - s.NoError(err) + s.Require().NoError(err) s.T().Cleanup(func() { _ = s.KubeClient.CoreV1().ServiceAccounts(fixtures.Namespace).Delete(ctx, "artgc-role-test-sa", metav1.DeleteOptions{}) }) @@ -682,7 +683,7 @@ func (s *ArtifactsSuite) TestMainLog() { WaitForWorkflow(fixtures.ToBeSucceeded). Then(). ExpectArtifact("-", "main-logs", "my-bucket", func(t *testing.T, object minio.ObjectInfo, err error) { - assert.NoError(t, err) + require.NoError(t, err) }) }) s.Run("ActiveDeadlineSeconds", func() { @@ -693,7 +694,7 @@ func (s *ArtifactsSuite) TestMainLog() { WaitForWorkflow(fixtures.ToBeFailed). Then(). ExpectArtifact("-", "main-logs", "my-bucket", func(t *testing.T, object minio.ObjectInfo, err error) { - assert.NoError(t, err) + require.NoError(t, err) }) }) } diff --git a/test/e2e/cli_test.go b/test/e2e/cli_test.go index 1fcc63886848..6625fcfa234b 100644 --- a/test/e2e/cli_test.go +++ b/test/e2e/cli_test.go @@ -12,6 +12,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -77,7 +78,7 @@ func (s *CLISuite) AfterTest(suiteName, testName string) { func (s *CLISuite) TestCompletion() { s.Given().RunCli([]string{"completion", "bash"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) assert.Contains(t, output, "bash completion for argo") }) } @@ -86,17 +87,15 @@ func (s *CLISuite) TestLogLevels() { s.Run("Verbose", func() { s.Given(). RunCli([]string{"-v", "list"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "CLI version", "comment version header") - } + require.NoError(t, err) + assert.Contains(t, output, "CLI version", "comment version header") }) }) s.Run("LogLevel", func() { s.Given(). RunCli([]string{"--loglevel=debug", "list"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "CLI version", "comment version header") - } + require.NoError(t, err) + assert.Contains(t, output, "CLI version", "comment version header") }) }) } @@ -107,25 +106,22 @@ func (s *CLISuite) TestGLogLevels() { s.Run("Verbose", func() { s.Given(). RunCli([]string{"-v", "list"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, expected, "glog output") - } + require.NoError(t, err) + assert.Contains(t, output, expected, "glog output") }) }) s.Run("LogLevel", func() { s.Given(). RunCli([]string{"--loglevel=debug", "list"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.NotContains(t, output, expected, "glog output") - } + require.NoError(t, err) + assert.NotContains(t, output, expected, "glog output") }) }) s.Run("GLogLevel", func() { s.Given(). RunCli([]string{"--gloglevel=6", "list"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, expected, "glog output") - } + require.NoError(t, err) + assert.Contains(t, output, expected, "glog output") }) }) } @@ -135,48 +131,44 @@ func (s *CLISuite) TestVersion() { s.Run("NoError", func() { s.Given(). RunCli([]string{"version"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) }) }) s.Run("Default", func() { s.Given(). RunCli([]string{"version"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - lines := strings.Split(output, "\n") - if assert.Len(t, lines, 17) { - assert.Contains(t, lines[0], "argo:") - assert.Contains(t, lines[1], "BuildDate:") - assert.Contains(t, lines[2], "GitCommit:") - assert.Contains(t, lines[3], "GitTreeState:") - assert.Contains(t, lines[4], "GitTag:") - assert.Contains(t, lines[5], "GoVersion:") - assert.Contains(t, lines[6], "Compiler:") - assert.Contains(t, lines[7], "Platform:") - assert.Contains(t, lines[8], "argo-server:") - assert.Contains(t, lines[9], "BuildDate:") - assert.Contains(t, lines[10], "GitCommit:") - assert.Contains(t, lines[11], "GitTreeState:") - assert.Contains(t, lines[12], "GitTag:") - assert.Contains(t, lines[13], "GoVersion:") - assert.Contains(t, lines[14], "Compiler:") - assert.Contains(t, lines[15], "Platform:") - } - // these are the defaults - we should never see these - assert.NotContains(t, output, "argo: v0.0.0+unknown") - assert.NotContains(t, output, " BuildDate: 1970-01-01T00:00:00Z") - } + require.NoError(t, err) + lines := strings.Split(output, "\n") + require.Len(t, lines, 17) + assert.Contains(t, lines[0], "argo:") + assert.Contains(t, lines[1], "BuildDate:") + assert.Contains(t, lines[2], "GitCommit:") + assert.Contains(t, lines[3], "GitTreeState:") + assert.Contains(t, lines[4], "GitTag:") + assert.Contains(t, lines[5], "GoVersion:") + assert.Contains(t, lines[6], "Compiler:") + assert.Contains(t, lines[7], "Platform:") + assert.Contains(t, lines[8], "argo-server:") + assert.Contains(t, lines[9], "BuildDate:") + assert.Contains(t, lines[10], "GitCommit:") + assert.Contains(t, lines[11], "GitTreeState:") + assert.Contains(t, lines[12], "GitTag:") + assert.Contains(t, lines[13], "GoVersion:") + assert.Contains(t, lines[14], "Compiler:") + assert.Contains(t, lines[15], "Platform:") + // these are the defaults - we should never see these + assert.NotContains(t, output, "argo: v0.0.0+unknown") + assert.NotContains(t, output, " BuildDate: 1970-01-01T00:00:00Z") }) }) s.Run("Short", func() { s.Given(). RunCli([]string{"version", "--short"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - lines := strings.Split(output, "\n") - if assert.Len(t, lines, 3) { - assert.Contains(t, lines[0], "argo:") - assert.Contains(t, lines[1], "argo-server:") - } - } + require.NoError(t, err) + lines := strings.Split(output, "\n") + require.Len(t, lines, 3) + assert.Contains(t, lines[0], "argo:") + assert.Contains(t, lines[1], "argo-server:") }) }) } @@ -196,31 +188,28 @@ func (s *CLISuite) TestKUBE() { func (s *CLISuite) TestSubmitDryRun() { s.Given(). RunCli([]string{"submit", "smoke/basic.yaml", "--dry-run", "-o", "yaml", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "generateName: basic") - // dry-run should never get a UID - assert.NotContains(t, output, "uid:") - } + require.NoError(t, err) + assert.Contains(t, output, "generateName: basic") + // dry-run should never get a UID + assert.NotContains(t, output, "uid:") }) } func (s *CLISuite) TestSubmitInvalidWf() { s.Given(). RunCli([]string{"submit", "smoke/basic-invalid.yaml", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.Error(t, err) { - assert.Contains(t, output, "yaml file at index 0 is not valid:") - } + require.Error(t, err) + assert.Contains(t, output, "yaml file at index 0 is not valid:") }) } func (s *CLISuite) TestSubmitServerDryRun() { s.Given(). RunCli([]string{"submit", "smoke/basic.yaml", "--server-dry-run", "-o", "yaml", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "name: basic") - // server-dry-run should get a UID - assert.Contains(t, output, "uid:") - } + require.NoError(t, err) + assert.Contains(t, output, "name: basic") + // server-dry-run should get a UID + assert.Contains(t, output, "uid:") }) } @@ -230,11 +219,10 @@ func (s *CLISuite) TestSubmitWorkflowTemplateDryRun() { When(). CreateWorkflowTemplates(). RunCli([]string{"submit", "--dry-run", "--from", "workflowtemplate/workflow-template-whalesay-template", "-o", "yaml", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "generateName: workflow-template-whalesay-template-") - // dry-run should never get a UID - assert.NotContains(t, output, "uid:") - } + require.NoError(t, err) + assert.Contains(t, output, "generateName: workflow-template-whalesay-template-") + // dry-run should never get a UID + assert.NotContains(t, output, "uid:") }). Then(). ExpectWorkflowList(metav1.ListOptions{LabelSelector: common.LabelKeyWorkflowTemplate + "=workflow-template-whalesay-template"}, func(t *testing.T, wfList *wfv1.WorkflowList) { @@ -248,11 +236,10 @@ func (s *CLISuite) TestSubmitWorkflowTemplateServerDryRun() { When(). CreateWorkflowTemplates(). RunCli([]string{"submit", "--server-dry-run", "--from", "workflowtemplate/workflow-template-whalesay-template", "-o", "yaml", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "generateName: workflow-template-whalesay-template-") - // server-dry-run should get a UID - assert.Contains(t, output, "uid:") - } + require.NoError(t, err) + assert.Contains(t, output, "generateName: workflow-template-whalesay-template-") + // server-dry-run should get a UID + assert.Contains(t, output, "uid:") }). Then(). ExpectWorkflowList(metav1.ListOptions{LabelSelector: common.LabelKeyWorkflowTemplate + "=workflow-template-whalesay-template"}, func(t *testing.T, wfList *wfv1.WorkflowList) { @@ -267,19 +254,19 @@ func (s *CLISuite) TestTokenArg() { s.setMode(KUBE) s.Run("ListWithBadToken", func() { s.Given().RunCli([]string{"list", "--user", "fake_token_user", "--token", "badtoken"}, func(t *testing.T, output string, err error) { - assert.Error(t, err) + require.Error(t, err) }) }) var goodToken string s.Run("GetSAToken", func() { token, err := s.GetServiceAccountToken() - s.NoError(err) + s.Require().NoError(err) goodToken = token }) s.Run("ListWithGoodToken", func() { s.Given().RunCli([]string{"list", "--user", "fake_token_user", "--token", goodToken}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) }) }) } @@ -302,33 +289,29 @@ func (s *CLISuite) TestLogs() { s.Run("FollowWorkflowLogs", func() { s.Given(). RunCli([]string{"logs", name, "--follow"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, ":) Hello Argo!") - } + require.NoError(t, err) + assert.Contains(t, output, ":) Hello Argo!") }) }) s.Run("FollowPodLogs", func() { s.Given(). RunCli([]string{"logs", name, name, "--follow"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, ":) Hello Argo!") - } + require.NoError(t, err) + assert.Contains(t, output, ":) Hello Argo!") }) }) s.Run("ContainerLogs", func() { s.Given(). RunCli([]string{"logs", name, name, "-c", "wait"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Executor") - } + require.NoError(t, err) + assert.Contains(t, output, "Executor") }) }) s.Run("Since", func() { s.Given(). RunCli([]string{"logs", name, "--since=1s"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.NotContains(t, output, ":) Hello Argo!") - } + require.NoError(t, err) + assert.NotContains(t, output, ":) Hello Argo!") }) }) s.Run("SinceTime", func() { @@ -336,25 +319,22 @@ func (s *CLISuite) TestLogs() { defer s.setMode(DEFAULT) s.Given(). RunCli([]string{"logs", name, "--since-time=" + time.Now().Format(time.RFC3339)}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.NotContains(t, output, ":) Hello Argo!") - } + require.NoError(t, err) + assert.NotContains(t, output, ":) Hello Argo!") }) }) s.Run("TailLines", func() { s.Given(). RunCli([]string{"logs", name, "--tail=0"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.NotContains(t, output, ":) Hello Argo!") - } + require.NoError(t, err) + assert.NotContains(t, output, ":) Hello Argo!") }) }) s.Run("Grep", func() { s.Given(). RunCli([]string{"logs", name, "--grep=no"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.NotContains(t, output, ":) Hello Argo!") - } + require.NoError(t, err) + assert.NotContains(t, output, ":) Hello Argo!") }) }) s.Run("CompletedWorkflow", func() { @@ -363,9 +343,8 @@ func (s *CLISuite) TestLogs() { WaitForWorkflow(). Then(). RunCli([]string{"logs", name, "--tail=10"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, ":) Hello Argo!") - } + require.NoError(t, err) + assert.Contains(t, output, ":) Hello Argo!") }) }) } @@ -392,41 +371,37 @@ func (s *CLISuite) TestLogProblems() { Then(). // logs should come in order RunCli([]string{"logs", "@latest", "--follow"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - lines := toLines(output) - if assert.Len(t, lines, 5) { - assert.Contains(t, lines[0], "one") - assert.Contains(t, lines[1], "two") - assert.Contains(t, lines[2], "three") - assert.Contains(t, lines[3], "four") - assert.Contains(t, lines[4], "five") - } - } + require.NoError(t, err) + lines := toLines(output) + require.Len(t, lines, 5) + assert.Contains(t, lines[0], "one") + assert.Contains(t, lines[1], "two") + assert.Contains(t, lines[2], "three") + assert.Contains(t, lines[3], "four") + assert.Contains(t, lines[4], "five") }). When(). // Next check that all log entries and received and in the correct order. WaitForWorkflow(). Then(). RunCli([]string{"logs", "@latest"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - lines := toLines(output) - if assert.Len(t, lines, 5) { - assert.Contains(t, lines[0], "one") - assert.Contains(t, lines[1], "two") - assert.Contains(t, lines[2], "three") - assert.Contains(t, lines[3], "four") - assert.Contains(t, lines[4], "five") - } - } + require.NoError(t, err) + lines := toLines(output) + require.Len(t, lines, 5) + assert.Contains(t, lines[0], "one") + assert.Contains(t, lines[1], "two") + assert.Contains(t, lines[2], "three") + assert.Contains(t, lines[3], "four") + assert.Contains(t, lines[4], "five") }) } func (s *CLISuite) TestParametersFile() { err := os.WriteFile("/tmp/parameters-file.yaml", []byte("message: hello"), os.ModePerm) - s.NoError(err) + s.Require().NoError(err) s.Given(). RunCli([]string{"submit", "testdata/parameters-workflow.yaml", "-l", "workflows.argoproj.io/test=true", "--parameter-file=/tmp/parameters-file.yaml"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) assert.Contains(t, output, "message: hello") }) } @@ -434,74 +409,67 @@ func (s *CLISuite) TestParametersFile() { func (s *CLISuite) TestRoot() { s.Run("Submit", func() { s.Given().RunCli([]string{"submit", "testdata/basic-workflow.yaml", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "ServiceAccount:") - assert.Contains(t, output, "Status:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "ServiceAccount:") + assert.Contains(t, output, "Status:") + assert.Contains(t, output, "Created:") }) }) s.Run("List", func() { s.Run("DefaultOutput", func() { s.Given(). RunCli([]string{"list"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "NAME") - assert.Contains(t, output, "STATUS") - assert.Contains(t, output, "AGE") - assert.Contains(t, output, "DURATION") - assert.Contains(t, output, "PRIORITY") - } + require.NoError(t, err) + assert.Contains(t, output, "NAME") + assert.Contains(t, output, "STATUS") + assert.Contains(t, output, "AGE") + assert.Contains(t, output, "DURATION") + assert.Contains(t, output, "PRIORITY") }) }) s.Run("NameOutput", func() { s.Given(). RunCli([]string{"list", "-o", "name"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.NotContains(t, output, "NAME") - } + require.NoError(t, err) + assert.NotContains(t, output, "NAME") }) }) s.Run("WideOutput", func() { s.Given(). RunCli([]string{"list", "-o", "wide"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "PARAMETERS") - } + require.NoError(t, err) + assert.Contains(t, output, "PARAMETERS") }) }) s.Run("JSONOutput", func() { s.Given(). RunCli([]string{"list", "-o", "json"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - list := wfv1.Workflows{} - assert.NoError(t, json.Unmarshal([]byte(output), &list)) - assert.Len(t, list, 1) - } + require.NoError(t, err) + list := wfv1.Workflows{} + require.NoError(t, json.Unmarshal([]byte(output), &list)) + assert.Len(t, list, 1) }) }) s.Run("YAMLOutput", func() { s.Given(). RunCli([]string{"list", "-o", "yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - list := wfv1.Workflows{} - assert.NoError(t, yaml.UnmarshalStrict([]byte(output), &list)) - assert.Len(t, list, 1) - } + require.NoError(t, err) + list := wfv1.Workflows{} + require.NoError(t, yaml.UnmarshalStrict([]byte(output), &list)) + assert.Len(t, list, 1) }) }) }) s.Run("Get", func() { s.Given().RunCli([]string{"get", "@latest"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "ServiceAccount:") - assert.Contains(t, output, "Status:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "ServiceAccount:") + assert.Contains(t, output, "Status:") + assert.Contains(t, output, "Created:") }) }) s.Run("Delete", func() { @@ -514,7 +482,7 @@ func (s *CLISuite) TestRoot() { When(). CreateCronWorkflow(). RunCli([]string{"submit", "--from", "cronworkflow/test-cron-wf-basic", "--scheduled-time", "2006-01-02T15:04:05-07:00", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) assert.Contains(t, output, "Name: test-cron-wf-basic-") }). WaitForWorkflow(fixtures.ToBeSucceeded). @@ -531,7 +499,7 @@ func (s *CLISuite) TestSubmitClusterWorkflowTemplate() { When(). CreateClusterWorkflowTemplates(). RunCli([]string{"submit", "--from", "clusterworkflowtemplate/cluster-workflow-template-whalesay-template", "--name", "my-wf", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) }). WaitForWorkflow(fixtures.ToBeSucceeded) } @@ -543,14 +511,12 @@ func (s *CLISuite) TestWorkflowSuspendResume() { SubmitWorkflow(). WaitForWorkflow(fixtures.ToStart). RunCli([]string{"suspend", "@latest"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "workflow @latest suspended") - } + require.NoError(t, err) + assert.Contains(t, output, "workflow @latest suspended") }). RunCli([]string{"resume", "@latest"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "workflow @latest resumed") - } + require.NoError(t, err) + assert.Contains(t, output, "workflow @latest resumed") }). WaitForWorkflow(fixtures.ToBeSucceeded) } @@ -564,17 +530,15 @@ func (s *CLISuite) TestNodeSuspendResume() { return wf.Status.AnyActiveSuspendNode(), "suspended node" })). RunCli([]string{"resume", "@latest", "--node-field-selector", "inputs.parameters.tag.value=suspend1-tag1"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "workflow @latest resumed") - } + require.NoError(t, err) + assert.Contains(t, output, "workflow @latest resumed") }). WaitForWorkflow(fixtures.Condition(func(wf *wfv1.Workflow) (bool, string) { return wf.Status.AnyActiveSuspendNode(), "suspended node" })). RunCli([]string{"stop", "@latest", "--node-field-selector", "inputs.parameters.tag.value=suspend2-tag1", "--message", "because"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "workflow node-suspend-.* stopped", output) - } + require.NoError(t, err) + assert.Regexp(t, "workflow node-suspend-.* stopped", output) }). WaitForWorkflow(fixtures.ToBeFailed). Then(). @@ -594,9 +558,8 @@ func (s *CLISuite) TestWorkflowDeleteByName() { name = metadata.Name }). RunCli([]string{"delete", name}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "Workflow 'basic-.*' deleted", output) - } + require.NoError(t, err) + assert.Regexp(t, "Workflow 'basic-.*' deleted", output) }) } @@ -611,9 +574,8 @@ func (s *CLISuite) TestWorkflowDeleteByFieldSelector() { name = metadata.Name }). RunCli([]string{"delete", "--field-selector", fmt.Sprintf("metadata.name=%s", name)}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "Workflow 'basic-.*' deleted", output) - } + require.NoError(t, err) + assert.Regexp(t, "Workflow 'basic-.*' deleted", output) }) } @@ -621,9 +583,8 @@ func (s *CLISuite) TestWorkflowDeleteDryRun() { s.Given(). When(). RunCli([]string{"delete", "--dry-run", "basic"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Workflow 'basic' deleted (dry-run)") - } + require.NoError(t, err) + assert.Contains(t, output, "Workflow 'basic' deleted (dry-run)") }) } @@ -633,9 +594,8 @@ func (s *CLISuite) TestWorkflowDeleteNothing() { When(). SubmitWorkflow(). RunCli([]string{"delete"}, func(t *testing.T, output string, err error) { - if assert.EqualError(t, err, "exit status 1") { - assert.NotContains(t, output, "deleted") - } + require.EqualError(t, err, "exit status 1") + assert.NotContains(t, output, "deleted") }) } @@ -643,9 +603,8 @@ func (s *CLISuite) TestWorkflowDeleteNotFound() { s.Given(). When(). RunCli([]string{"delete", "not-found"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Workflow 'not-found' not found") - } + require.NoError(t, err) + assert.Contains(t, output, "Workflow 'not-found' not found") }) } @@ -656,9 +615,8 @@ func (s *CLISuite) TestWorkflowDeleteAll() { SubmitWorkflow(). Given(). RunCli([]string{"delete", "--all", "-l", "workflows.argoproj.io/test"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "Workflow 'basic-.*' deleted", output) - } + require.NoError(t, err) + assert.Regexp(t, "Workflow 'basic-.*' deleted", output) }) } @@ -669,18 +627,16 @@ func (s *CLISuite) TestWorkflowDeleteCompleted() { SubmitWorkflow(). Given(). RunCli([]string{"delete", "--completed", "-l", "workflows.argoproj.io/test"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - // nothing should be deleted yet - assert.NotContains(t, output, "deleted") - } + require.NoError(t, err) + // nothing should be deleted yet + assert.NotContains(t, output, "deleted") }). When(). WaitForWorkflow(). Given(). RunCli([]string{"delete", "--completed", "-l", "workflows.argoproj.io/test"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "deleted") - } + require.NoError(t, err) + assert.Contains(t, output, "deleted") }) } @@ -692,20 +648,18 @@ func (s *CLISuite) TestWorkflowDeleteResubmitted() { WaitForWorkflow(). Given(). RunCli([]string{"resubmit", "--memoized", "@latest"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "ServiceAccount:") - assert.Contains(t, output, "Status:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "ServiceAccount:") + assert.Contains(t, output, "Status:") + assert.Contains(t, output, "Created:") }). When(). Given(). RunCli([]string{"delete", "--resubmitted", "-l", "workflows.argoproj.io/test"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "deleted") - } + require.NoError(t, err) + assert.Contains(t, output, "deleted") }) } @@ -717,15 +671,13 @@ func (s *CLISuite) TestWorkflowDeleteOlder() { WaitForWorkflow(). Given(). RunCli([]string{"delete", "--older", "1d", "-l", "workflows.argoproj.io/test"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - // nothing over a day should be deleted - assert.NotContains(t, output, "deleted") - } + require.NoError(t, err) + // nothing over a day should be deleted + assert.NotContains(t, output, "deleted") }). RunCli([]string{"delete", "--older", "0s", "-l", "workflows.argoproj.io/test"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "deleted") - } + require.NoError(t, err) + assert.Contains(t, output, "deleted") }) } @@ -736,38 +688,33 @@ func (s *CLISuite) TestWorkflowDeleteByPrefix() { SubmitWorkflow(). Given(). RunCli([]string{"delete", "--prefix", "missing-prefix", "-l", "workflows.argoproj.io/test"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - // nothing should be deleted - assert.NotContains(t, output, "deleted") - } + require.NoError(t, err) + // nothing should be deleted + assert.NotContains(t, output, "deleted") }). RunCli([]string{"delete", "--prefix", "basic", "-l", "workflows.argoproj.io/test"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "deleted") - } + require.NoError(t, err) + assert.Contains(t, output, "deleted") }) } func (s *CLISuite) TestWorkflowLint() { s.Run("LintFile", func() { s.Given().RunCli([]string{"lint", "smoke/basic.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "no linting errors found") - } + require.NoError(t, err) + assert.Contains(t, output, "no linting errors found") }) }) s.Run("LintFileEmptyParamDAG", func() { s.Given().RunCli([]string{"lint", "expectedfailures/empty-parameter-dag.yaml"}, func(t *testing.T, output string, err error) { - if assert.EqualError(t, err, "exit status 1") { - assert.Contains(t, output, "templates.abc.tasks.a templates.whalesay inputs.parameters.message was not supplied") - } + require.EqualError(t, err, "exit status 1") + assert.Contains(t, output, "templates.abc.tasks.a templates.whalesay inputs.parameters.message was not supplied") }) }) s.Run("LintFileEmptyParamSteps", func() { s.Given().RunCli([]string{"lint", "expectedfailures/empty-parameter-steps.yaml"}, func(t *testing.T, output string, err error) { - if assert.EqualError(t, err, "exit status 1") { - assert.Contains(t, output, "templates.abc.steps[0].a templates.whalesay inputs.parameters.message was not supplied") - } + require.EqualError(t, err, "exit status 1") + assert.Contains(t, output, "templates.abc.steps[0].a templates.whalesay inputs.parameters.message was not supplied") }) }) s.Run("LintFileWithTemplate", func() { @@ -777,9 +724,8 @@ func (s *CLISuite) TestWorkflowLint() { CreateWorkflowTemplates(). Given(). RunCli([]string{"lint", "smoke/hello-world-workflow-tmpl.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "no linting errors found") - } + require.NoError(t, err) + assert.Contains(t, output, "no linting errors found") }) }) s.Run("LintDir", func() { @@ -794,60 +740,53 @@ func (s *CLISuite) TestWorkflowLint() { s.CheckError(err) s.Given(). RunCli([]string{"lint", tmp}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "no linting errors found") - } + require.NoError(t, err) + assert.Contains(t, output, "no linting errors found") }) }) s.Run("Different Kind", func() { s.Given(). RunCli([]string{"lint", "testdata/workflow-template-nested-template.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "no linting errors found") - } + require.NoError(t, err) + assert.Contains(t, output, "no linting errors found") }) }) s.Run("Lint Only Workflows", func() { s.Given(). RunCli([]string{"lint", "--kinds", "wf", "testdata/workflow-template-nested-template.yaml"}, func(t *testing.T, output string, err error) { - if assert.Error(t, err) { - assert.Contains(t, output, "found nothing to lint in the specified paths, failing...") - } + require.Error(t, err) + assert.Contains(t, output, "found nothing to lint in the specified paths, failing...") }) }) s.Run("All Kinds", func() { s.Given(). RunCli([]string{"lint", "testdata/malformed/malformed-workflowtemplate-2.yaml"}, func(t *testing.T, output string, err error) { - if assert.Error(t, err) { - assert.Contains(t, output, "spec.templates[0].name is required") - assert.Contains(t, output, "1 linting errors found!") - } + require.Error(t, err) + assert.Contains(t, output, "spec.templates[0].name is required") + assert.Contains(t, output, "1 linting errors found!") }) }) s.Run("Valid", func() { s.Given(). RunCli([]string{"lint", "testdata/exit-1.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "no linting errors found") - } + require.NoError(t, err) + assert.Contains(t, output, "no linting errors found") }) }) s.Run("Invalid", func() { s.Given(). RunCli([]string{"lint", "expectedfailures/empty-parameter-dag.yaml"}, func(t *testing.T, output string, err error) { - if assert.Error(t, err) { - assert.Contains(t, output, "1 linting errors found!") - assert.Contains(t, output, "templates.abc.tasks.a templates.whalesay inputs.parameters.message was not supplied") - } + require.Error(t, err) + assert.Contains(t, output, "1 linting errors found!") + assert.Contains(t, output, "templates.abc.tasks.a templates.whalesay inputs.parameters.message was not supplied") }) }) s.Run("Lint Only CronWorkflows", func() { s.Given(). RunCli([]string{"lint", "--kinds", "cronwf", "cron/cron-and-malformed-template.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "no linting errors found") - } + require.NoError(t, err) + assert.Contains(t, output, "no linting errors found") }) }) } @@ -856,9 +795,8 @@ func (s *CLISuite) TestWorkflowOfflineLint() { s.setMode(OFFLINE) s.Run("LintFile", func() { s.Given().RunCli([]string{"lint", "--offline=true", "--kinds=workflows", "smoke/basic.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "no linting errors found") - } + require.NoError(t, err) + assert.Contains(t, output, "no linting errors found") }) }) } @@ -875,9 +813,8 @@ func (s *CLISuite) TestWorkflowRetry() { return wf.Status.AnyActiveSuspendNode(), "suspended node" }), time.Second*90). RunCli([]string{"terminate", "@latest"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "workflow retry-test-.* terminated", output) - } + require.NoError(t, err) + assert.Regexp(t, "workflow retry-test-.* terminated", output) }). WaitForWorkflow(fixtures.Condition(func(wf *wfv1.Workflow) (bool, string) { retryTime = wf.Status.FinishedAt @@ -885,10 +822,9 @@ func (s *CLISuite) TestWorkflowRetry() { })). Wait(3*time.Second). RunCli([]string{"retry", "@latest", "--restart-successful", "--node-field-selector", "templateName==steps-inner"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err, output) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - } + require.NoError(t, err, output) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") }). WaitForWorkflow(fixtures.Condition(func(wf *wfv1.Workflow) (bool, string) { return wf.Status.AnyActiveSuspendNode(), "suspended node" @@ -912,7 +848,7 @@ func (s *CLISuite) TestWorkflowRetryFailedWorkflow() { SubmitWorkflow(). WaitForWorkflow(fixtures.ToBeFailed). RunCli([]string{"retry", "-l", "workflows.argoproj.io/workflow=fail-first-pass-second-workflow", "--namespace=argo"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err, output) + require.NoError(t, err, output) }). WaitForWorkflow(fixtures.ToBeSucceeded) } @@ -925,10 +861,9 @@ func (s *CLISuite) TestWorkflowRetryNestedDag() { WaitForWorkflow(fixtures.ToBeFailed). Then(). RunCli([]string{"retry", "retry-nested-dag", "--restart-successful", "--node-field-selector", "name=retry-nested-dag.dag1-step2.dag2-step1.dag3-step1"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err, output) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - } + require.NoError(t, err, output) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") }). When(). WaitForWorkflow(fixtures.ToBeFailed). @@ -948,10 +883,9 @@ func (s *CLISuite) TestWorkflowRetryWithRecreatedPVC() { WaitForWorkflow(fixtures.ToBeFailed). Then(). RunCli([]string{"retry", "retry-with-recreated-pvc"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err, output) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - } + require.NoError(t, err, output) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") }). When(). WaitForWorkflow(fixtures.ToBeFailed). @@ -977,10 +911,9 @@ func (s *CLISuite) TestRetryWorkflowWithContinueOn() { assert.Len(t, status.Nodes, 7) }). RunCli([]string{"retry", workflowName}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err, output) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - } + require.NoError(t, err, output) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") }) s.Given(). @@ -1006,9 +939,8 @@ func (s *CLISuite) TestWorkflowStop() { SubmitWorkflow(). Then(). RunCli([]string{"stop", "@latest"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "workflow basic-.* stopped", output) - } + require.NoError(t, err) + assert.Regexp(t, "workflow basic-.* stopped", output) }) } @@ -1018,9 +950,8 @@ func (s *CLISuite) TestWorkflowStopDryRun() { When(). SubmitWorkflow(). RunCli([]string{"stop", "--dry-run", "basic"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "workflow basic stopped \\(dry-run\\)", output) - } + require.NoError(t, err) + assert.Regexp(t, "workflow basic stopped \\(dry-run\\)", output) }) } @@ -1030,9 +961,8 @@ func (s *CLISuite) TestWorkflowStopBySelector() { When(). SubmitWorkflow(). RunCli([]string{"stop", "--selector", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "workflow basic-.* stopped", output) - } + require.NoError(t, err) + assert.Regexp(t, "workflow basic-.* stopped", output) }) } @@ -1042,9 +972,8 @@ func (s *CLISuite) TestWorkflowStopByFieldSelector() { When(). SubmitWorkflow(). RunCli([]string{"stop", "--field-selector", "metadata.namespace=argo"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "workflow basic-.* stopped", output) - } + require.NoError(t, err) + assert.Regexp(t, "workflow basic-.* stopped", output) }) } @@ -1055,9 +984,8 @@ func (s *CLISuite) TestWorkflowTerminate() { SubmitWorkflow(). Then(). RunCli([]string{"terminate", "@latest"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "workflow basic-.* terminated", output) - } + require.NoError(t, err) + assert.Regexp(t, "workflow basic-.* terminated", output) }) } @@ -1067,9 +995,8 @@ func (s *CLISuite) TestWorkflowTerminateDryRun() { When(). SubmitWorkflow(). RunCli([]string{"terminate", "--dry-run", "@latest"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "workflow @latest terminated \\(dry-run\\)", output) - } + require.NoError(t, err) + assert.Regexp(t, "workflow @latest terminated \\(dry-run\\)", output) }) } @@ -1079,9 +1006,8 @@ func (s *CLISuite) TestWorkflowTerminateBySelector() { When(). SubmitWorkflow(). RunCli([]string{"terminate", "--selector", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "workflow basic-.* terminated", output) - } + require.NoError(t, err) + assert.Regexp(t, "workflow basic-.* terminated", output) }) } @@ -1091,9 +1017,8 @@ func (s *CLISuite) TestWorkflowTerminateByFieldSelector() { When(). SubmitWorkflow(). RunCli([]string{"terminate", "--field-selector", "metadata.namespace=argo"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "workflow basic-.* terminated", output) - } + require.NoError(t, err) + assert.Regexp(t, "workflow basic-.* terminated", output) }) } @@ -1108,9 +1033,8 @@ func (s *CLISuite) TestWorkflowWait() { name = metadata.Name }). RunCli([]string{"wait", name}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Regexp(t, "basic-.* Succeeded", output) - } + require.NoError(t, err) + assert.Regexp(t, "basic-.* Succeeded", output) }) } @@ -1121,31 +1045,28 @@ func (s *CLISuite) TestWorkflowWatch() { SubmitWorkflow(). Then(). RunCli([]string{"watch", "@latest"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name: ") - } + require.NoError(t, err) + assert.Contains(t, output, "Name: ") }) } func (s *CLISuite) TestTemplateCommands() { s.Run("LintWithoutArgs", func() { s.Given().RunCli([]string{"template", "lint"}, func(t *testing.T, output string, err error) { - if assert.Error(t, err) { - assert.Contains(t, output, "Usage:") - } + require.Error(t, err) + assert.Contains(t, output, "Usage:") }) }) s.Run("Lint", func() { s.Given().RunCli([]string{"template", "lint", "testdata/basic-workflowtemplate.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "no linting errors found!") - } + require.NoError(t, err) + assert.Contains(t, output, "no linting errors found!") }) }) s.Run("DirLintWithInvalidWFT", func() { s.Given().RunCli([]string{"template", "lint", "testdata/workflow-templates"}, func(t *testing.T, output string, err error) { - assert.Error(t, err) + require.Error(t, err) assert.Contains(t, output, "invalid-workflowtemplate.yaml") assert.Contains(t, output, `unknown field "spec.entrypoints"`) assert.Contains(t, output, "linting errors found!") @@ -1154,84 +1075,75 @@ func (s *CLISuite) TestTemplateCommands() { s.Run("Create", func() { s.Given().RunCli([]string{"template", "create", "testdata/basic-workflowtemplate.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "Created:") }) }) s.Run("List", func() { s.Given().RunCli([]string{"template", "list"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "NAME") - } + require.NoError(t, err) + assert.Contains(t, output, "NAME") }) }) s.Run("Get", func() { s.Given().RunCli([]string{"template", "get", "not-found"}, func(t *testing.T, output string, err error) { - if assert.EqualError(t, err, "exit status 1") { - assert.Contains(t, output, `"not-found" not found`) - } + require.EqualError(t, err, "exit status 1") + assert.Contains(t, output, `"not-found" not found`) }).RunCli([]string{"template", "get", "basic"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "Created:") }) }) s.Run("Submit", func() { s.Given(). RunCli([]string{"submit", "--from", "workflowtemplate/basic"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "Created:") }) }) s.Run("Update", func() { s.Given(). RunCli([]string{"template", "update", "testdata/basic-workflowtemplate-update.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "Created:") }) }) s.Run("Get", func() { s.Given().RunCli([]string{"template", "get", "basic", "-o", "yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "entrypoint: main-2") - assert.Contains(t, output, "name: main-2") - } + require.NoError(t, err) + assert.Contains(t, output, "entrypoint: main-2") + assert.Contains(t, output, "name: main-2") }) }) s.Run("Update", func() { s.Given(). RunCli([]string{"template", "update", "testdata/basic-workflowtemplate.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "Created:") }) }) s.Run("Get", func() { s.Given().RunCli([]string{"template", "get", "basic", "-o", "yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "entrypoint: main") - assert.Contains(t, output, "name: main") - assert.NotContains(t, output, "entrypoint: main-2") - assert.NotContains(t, output, "name: main-2") - } + require.NoError(t, err) + assert.Contains(t, output, "entrypoint: main") + assert.Contains(t, output, "name: main") + assert.NotContains(t, output, "entrypoint: main-2") + assert.NotContains(t, output, "name: main-2") }) }) s.Run("Delete", func() { s.Given().RunCli([]string{"template", "delete", "basic"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) }) }) } @@ -1244,13 +1156,12 @@ func (s *CLISuite) TestWorkflowResubmit() { WaitForWorkflow(). Given(). RunCli([]string{"resubmit", "--memoized", "@latest"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "ServiceAccount:") - assert.Contains(t, output, "Status:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "ServiceAccount:") + assert.Contains(t, output, "Status:") + assert.Contains(t, output, "Created:") }) } @@ -1263,18 +1174,16 @@ func (s *CLISuite) TestWorkflowResubmitDAGWithDependencies() { WaitForWorkflow(fixtures.ToBeFailed). Then(). RunCli([]string{"resubmit", "--memoized", "@latest"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "ServiceAccount:") - assert.Contains(t, output, "Status:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "ServiceAccount:") + assert.Contains(t, output, "Status:") + assert.Contains(t, output, "Created:") }). RunCli([]string{"get", "@latest", "-o", "yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - wfString = output - } + require.NoError(t, err) + wfString = output }) s.Given(). @@ -1320,13 +1229,12 @@ func (s *CLISuite) TestWorkflowResubmitByLabelSelector() { WaitForWorkflow(). Given(). RunCli([]string{"resubmit", "--selector", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "ServiceAccount:") - assert.Contains(t, output, "Status:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "ServiceAccount:") + assert.Contains(t, output, "Status:") + assert.Contains(t, output, "Created:") }) } @@ -1338,46 +1246,41 @@ func (s *CLISuite) TestWorkflowResubmitByFieldSelector() { WaitForWorkflow(). Given(). RunCli([]string{"resubmit", "--field-selector", "metadata.namespace=argo"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "ServiceAccount:") - assert.Contains(t, output, "Status:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "ServiceAccount:") + assert.Contains(t, output, "Status:") + assert.Contains(t, output, "Created:") }) } func (s *CLISuite) TestCronCommands() { s.Run("Lint", func() { s.Given().RunCli([]string{"cron", "lint", "cron/basic.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "no linting errors found!") - } + require.NoError(t, err) + assert.Contains(t, output, "no linting errors found!") }) }) s.Run("Lint All Kinds", func() { s.Given().RunCli([]string{"lint", "cron/basic.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "no linting errors found!") - } + require.NoError(t, err) + assert.Contains(t, output, "no linting errors found!") }) }) s.Run("Different Kind", func() { s.Given(). RunCli([]string{"cron", "lint", "testdata/workflow-template-nested-template.yaml"}, func(t *testing.T, output string, err error) { - if assert.Error(t, err) { - assert.Contains(t, output, "found nothing to lint in the specified paths, failing...") - } + require.Error(t, err) + assert.Contains(t, output, "found nothing to lint in the specified paths, failing...") }) }) // Ignore other malformed kinds s.Run("IgnoreOtherKinds", func() { s.Given(). RunCli([]string{"cron", "lint", "cron/cron-and-malformed-template.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "no linting errors found!") - } + require.NoError(t, err) + assert.Contains(t, output, "no linting errors found!") }) }) @@ -1385,172 +1288,155 @@ func (s *CLISuite) TestCronCommands() { s.Run("AllCron", func() { s.Given(). RunCli([]string{"cron", "lint", "cron"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "no linting errors found!") - } + require.NoError(t, err) + assert.Contains(t, output, "no linting errors found!") }) }) s.Run("Create", func() { s.Given().RunCli([]string{"cron", "create", "cron/basic.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "Created:") - assert.Contains(t, output, "Schedule:") - assert.Contains(t, output, "Suspended:") - assert.Contains(t, output, "StartingDeadlineSeconds:") - assert.Contains(t, output, "ConcurrencyPolicy:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "Created:") + assert.Contains(t, output, "Schedule:") + assert.Contains(t, output, "Suspended:") + assert.Contains(t, output, "StartingDeadlineSeconds:") + assert.Contains(t, output, "ConcurrencyPolicy:") }) }) s.Run("Delete", func() { s.Given().RunCli([]string{"cron", "delete", "test-cron-wf-basic"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) }) }) s.Run("Create Schedule Override", func() { s.Given().RunCli([]string{"cron", "create", "cron/basic.yaml", "--schedule", "1 2 3 * *", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Schedule: 1 2 3 * *") - } + require.NoError(t, err) + assert.Contains(t, output, "Schedule: 1 2 3 * *") }) }) s.Run("Update", func() { s.Given(). RunCli([]string{"cron", "update", "cron/basic-update.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Schedule: 5 5 5 * *") - } + require.NoError(t, err) + assert.Contains(t, output, "Schedule: 5 5 5 * *") }) }) s.Run("Get", func() { s.Given().RunCli([]string{"cron", "get", "test-cron-wf-basic", "-o", "yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "5 5 5 * *") - assert.Contains(t, output, "Replace") - assert.Contains(t, output, "startingDeadlineSeconds: 10") - assert.Contains(t, output, "successfulJobsHistoryLimit: 5") - assert.Contains(t, output, "failedJobsHistoryLimit: 3") - assert.Contains(t, output, "argosay") - } + require.NoError(t, err) + assert.Contains(t, output, "5 5 5 * *") + assert.Contains(t, output, "Replace") + assert.Contains(t, output, "startingDeadlineSeconds: 10") + assert.Contains(t, output, "successfulJobsHistoryLimit: 5") + assert.Contains(t, output, "failedJobsHistoryLimit: 3") + assert.Contains(t, output, "argosay") }) }) s.Run("Update", func() { s.Given(). RunCli([]string{"cron", "update", "cron/basic-update-template.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Schedule: 5 5 5 * *") - } + require.NoError(t, err) + assert.Contains(t, output, "Schedule: 5 5 5 * *") }) }) s.Run("Get", func() { s.Given().RunCli([]string{"cron", "get", "test-cron-wf-basic", "-o", "yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "5 5 5 * *") - assert.Contains(t, output, "Replace") - assert.Contains(t, output, "whalesay") - assert.NotContains(t, output, "argosay") - } + require.NoError(t, err) + assert.Contains(t, output, "5 5 5 * *") + assert.Contains(t, output, "Replace") + assert.Contains(t, output, "whalesay") + assert.NotContains(t, output, "argosay") }) }) s.Run("Create Parameter Override", func() { s.Given().RunCli([]string{"cron", "create", "cron/param.yaml", "-p", "message=\"bar test passed\"", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "bar test passed") - } + require.NoError(t, err) + assert.Contains(t, output, "bar test passed") }) }) s.Run("Create Name Override", func() { s.Given().RunCli([]string{"cron", "create", "cron/basic.yaml", "--name", "basic-cron-wf-overridden-name", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, strings.Replace(output, " ", "", -1), "Name:basic-cron-wf-overridden-name") - } + require.NoError(t, err) + assert.Contains(t, strings.Replace(output, " ", "", -1), "Name:basic-cron-wf-overridden-name") }) }) s.Run("Create GenerateName Override", func() { s.Given().RunCli([]string{"cron", "create", "cron/basic.yaml", "--generate-name", "basic-cron-wf-overridden-generate-name-", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, strings.Replace(output, " ", "", -1), "Name:basic-cron-wf-overridden-generate-name-") - } + require.NoError(t, err) + assert.Contains(t, strings.Replace(output, " ", "", -1), "Name:basic-cron-wf-overridden-generate-name-") }) }) s.Run("List", func() { s.Given().RunCli([]string{"cron", "list"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "NAME") - assert.Contains(t, output, "AGE") - assert.Contains(t, output, "LAST RUN") - assert.Contains(t, output, "SCHEDULE") - assert.Contains(t, output, "SUSPENDED") - } + require.NoError(t, err) + assert.Contains(t, output, "NAME") + assert.Contains(t, output, "AGE") + assert.Contains(t, output, "LAST RUN") + assert.Contains(t, output, "SCHEDULE") + assert.Contains(t, output, "SUSPENDED") }) }) s.Run("List with labels", func() { // First create cron workflow with labels s.Given().RunCli([]string{"cron", "create", "cron/cron-workflow-with-labels.yaml"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) }). // Then create cron workflow without labels RunCli([]string{"cron", "create", "cron/basic.yaml", "--name", "cron-wf-without-labels"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) }). // Then check to make sure only cron workflow with labels shows up from 'argo cron list...' RunCli([]string{"cron", "list", "-l client=importantclient"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "NAME") - assert.Contains(t, output, "AGE") - assert.Contains(t, output, "LAST RUN") - assert.Contains(t, output, "SCHEDULE") - assert.Contains(t, output, "SUSPENDED") - assert.Contains(t, output, "test-cwf-with-labels") - assert.NotContains(t, output, "cron-wf-without-labels") - } + require.NoError(t, err) + assert.Contains(t, output, "NAME") + assert.Contains(t, output, "AGE") + assert.Contains(t, output, "LAST RUN") + assert.Contains(t, output, "SCHEDULE") + assert.Contains(t, output, "SUSPENDED") + assert.Contains(t, output, "test-cwf-with-labels") + assert.NotContains(t, output, "cron-wf-without-labels") }) }) s.Run("Suspend", func() { s.Given().RunCli([]string{"cron", "suspend", "test-cron-wf-basic"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "CronWorkflow 'test-cron-wf-basic' suspended") - } + require.NoError(t, err) + assert.Contains(t, output, "CronWorkflow 'test-cron-wf-basic' suspended") }) }) s.Run("Resume", func() { s.Given().RunCli([]string{"cron", "resume", "test-cron-wf-basic"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "CronWorkflow 'test-cron-wf-basic' resumed") - } + require.NoError(t, err) + assert.Contains(t, output, "CronWorkflow 'test-cron-wf-basic' resumed") }) }) s.Run("Get", func() { s.Given().RunCli([]string{"cron", "get", "not-found"}, func(t *testing.T, output string, err error) { - if assert.EqualError(t, err, "exit status 1") { - assert.Contains(t, output, `\"not-found\" not found`) - } + require.EqualError(t, err, "exit status 1") + assert.Contains(t, output, `\"not-found\" not found`) }).RunCli([]string{"cron", "get", "test-cron-wf-basic"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "Created:") - assert.Contains(t, output, "Schedule:") - assert.Contains(t, output, "Suspended:") - assert.Contains(t, output, "StartingDeadlineSeconds:") - assert.Contains(t, output, "ConcurrencyPolicy:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "Created:") + assert.Contains(t, output, "Schedule:") + assert.Contains(t, output, "Suspended:") + assert.Contains(t, output, "StartingDeadlineSeconds:") + assert.Contains(t, output, "ConcurrencyPolicy:") }) }) s.Run("Create Multiple Schedules", func() { s.Given().RunCli([]string{"cron", "create", "cron/multiple-schedules.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Schedule: * * * * *,*/2 * * * *") - } + require.NoError(t, err) + assert.Contains(t, output, "Schedule: * * * * *,*/2 * * * *") }) }) } @@ -1559,67 +1445,59 @@ func (s *CLISuite) TestClusterTemplateCommands() { s.Run("Create", func() { s.Given(). RunCli([]string{"cluster-template", "create", "smoke/cluster-workflow-template-whalesay-template.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "cluster-workflow-template-whalesay-template") - } + require.NoError(t, err) + assert.Contains(t, output, "cluster-workflow-template-whalesay-template") }) }) s.Run("Get", func() { s.Given(). RunCli([]string{"cluster-template", "get", "cluster-workflow-template-whalesay-template"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "cluster-workflow-template-whalesay-template") - } + require.NoError(t, err) + assert.Contains(t, output, "cluster-workflow-template-whalesay-template") }) }) s.Run("Update", func() { s.Given(). RunCli([]string{"cluster-template", "update", "smoke/cluster-workflow-template-whalesay-template-update.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "cluster-workflow-template-whalesay-template") - } + require.NoError(t, err) + assert.Contains(t, output, "cluster-workflow-template-whalesay-template") }) }) s.Run("Get", func() { s.Given(). RunCli([]string{"cluster-template", "get", "cluster-workflow-template-whalesay-template", "-o", "yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "cluster-workflow-template-whalesay-template") - assert.Contains(t, output, "Updated: {{inputs.parameters.message}}") - } + require.NoError(t, err) + assert.Contains(t, output, "cluster-workflow-template-whalesay-template") + assert.Contains(t, output, "Updated: {{inputs.parameters.message}}") }) }) s.Run("Update", func() { s.Given(). RunCli([]string{"cluster-template", "update", "smoke/cluster-workflow-template-whalesay-template-update-parameters.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "cluster-workflow-template-whalesay-template") - } + require.NoError(t, err) + assert.Contains(t, output, "cluster-workflow-template-whalesay-template") }) }) s.Run("Get", func() { s.Given(). RunCli([]string{"cluster-template", "get", "cluster-workflow-template-whalesay-template", "-o", "yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "cluster-workflow-template-whalesay-template") - assert.Contains(t, output, "thanks") - } + require.NoError(t, err) + assert.Contains(t, output, "cluster-workflow-template-whalesay-template") + assert.Contains(t, output, "thanks") }) }) s.Run("list", func() { s.Given(). RunCli([]string{"cluster-template", "list"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "cluster-workflow-template-whalesay-template") - } + require.NoError(t, err) + assert.Contains(t, output, "cluster-workflow-template-whalesay-template") }) }) s.Run("Delete", func() { s.Given(). RunCli([]string{"cluster-template", "delete", "cluster-workflow-template-whalesay-template"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "cluster-workflow-template-whalesay-template") - } + require.NoError(t, err) + assert.Contains(t, output, "cluster-workflow-template-whalesay-template") }) }) } @@ -1627,37 +1505,33 @@ func (s *CLISuite) TestClusterTemplateCommands() { func (s *CLISuite) TestWorkflowTemplateRefSubmit() { s.Run("CreateWFT", func() { s.Given().RunCli([]string{"template", "create", "smoke/workflow-template-whalesay-template.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "Created:") }) }) s.Run("CreateWF", func() { s.Given().RunCli([]string{"submit", "testdata/workflow-template-ref.yaml", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "Created:") }) }) s.Run("CreateCWFT", func() { s.Given().RunCli([]string{"cluster-template", "create", "smoke/cluster-workflow-template-whalesay-template.yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Created:") }) }) s.Run("CreateWFWithCWFTRef", func() { s.Given().RunCli([]string{"submit", "testdata/cluster-workflow-template-ref.yaml", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "Created:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "Created:") }) }) } @@ -1674,11 +1548,10 @@ func (s *CLISuite) workflowCopyArtifactTests(workflowFileName string) { WaitForWorkflow(). Given(). RunCli([]string{"cp", "@latest", "outputDir"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Created \"main.log\"") - assert.Contains(t, output, "Created \"hello_world.tgz\"") - assert.Contains(t, output, "Created \"bye_world.tgz\"") - } + require.NoError(t, err) + assert.Contains(t, output, "Created \"main.log\"") + assert.Contains(t, output, "Created \"hello_world.tgz\"") + assert.Contains(t, output, "Created \"bye_world.tgz\"") }) os.RemoveAll("outputDir") @@ -1689,11 +1562,10 @@ func (s *CLISuite) workflowCopyArtifactTests(workflowFileName string) { WaitForWorkflow(). Given(). RunCli([]string{"cp", "@latest", "outputDir", "--template-name", "bye"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Created \"main.log\"") - assert.Contains(t, output, "Created \"bye_world.tgz\"") - assert.NotContains(t, output, "Created \"hello_world.tgz\"") - } + require.NoError(t, err) + assert.Contains(t, output, "Created \"main.log\"") + assert.Contains(t, output, "Created \"bye_world.tgz\"") + assert.NotContains(t, output, "Created \"hello_world.tgz\"") }) os.RemoveAll("outputDir") @@ -1704,11 +1576,10 @@ func (s *CLISuite) workflowCopyArtifactTests(workflowFileName string) { WaitForWorkflow(). Given(). RunCli([]string{"cp", "@latest", "outputDir", "--artifact-name", "hello_world"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.NotContains(t, output, "Created \"main.log\"") - assert.NotContains(t, output, "Created \"bye_world.tgz\"") - assert.Contains(t, output, "Created \"hello_world.tgz\"") - } + require.NoError(t, err) + assert.NotContains(t, output, "Created \"main.log\"") + assert.NotContains(t, output, "Created \"bye_world.tgz\"") + assert.Contains(t, output, "Created \"hello_world.tgz\"") }) os.RemoveAll("outputDir") @@ -1719,18 +1590,17 @@ func (s *CLISuite) workflowCopyArtifactTests(workflowFileName string) { WaitForWorkflow(). Given(). RunCli([]string{"cp", "@latest", ".", "--path", "/{templateName}/{artifactName}/"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - //Assert everything was stored - assert.Contains(t, output, "Created \"main.log\"") - assert.Contains(t, output, "Created \"bye_world.tgz\"") - assert.Contains(t, output, "Created \"hello_world.tgz\"") - //Assert filepaths are correct - statStrip := func(f os.FileInfo, err error) error { - return err - } - assert.NoError(t, statStrip(os.Stat("bye/bye_world/bye_world.tgz"))) - assert.NoError(t, statStrip(os.Stat("hello/hello_world/hello_world.tgz"))) - } + require.NoError(t, err) + //Assert everything was stored + assert.Contains(t, output, "Created \"main.log\"") + assert.Contains(t, output, "Created \"bye_world.tgz\"") + assert.Contains(t, output, "Created \"hello_world.tgz\"") + //Assert filepaths are correct + statStrip := func(f os.FileInfo, err error) error { + return err + } + require.NoError(t, statStrip(os.Stat("bye/bye_world/bye_world.tgz"))) + require.NoError(t, statStrip(os.Stat("hello/hello_world/hello_world.tgz"))) }) os.RemoveAll("bye") os.RemoveAll("hello") @@ -1795,7 +1665,7 @@ func (s *CLISuite) TestResourceTemplateStopAndTerminate() { func (s *CLISuite) TestAuthToken() { s.Given().RunCli([]string{"auth", "token"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) assert.NotEmpty(t, output) }) } @@ -1814,40 +1684,37 @@ func (s *CLISuite) TestArchive() { s.Run("List", func() { s.Given(). RunCli([]string{"archive", "list", "--chunk-size", "1"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - lines := strings.Split(output, "\n") - assert.Contains(t, lines[0], "NAMESPACE") - assert.Contains(t, lines[0], "NAME") - assert.Contains(t, lines[0], "STATUS") - assert.Contains(t, lines[0], "UID") - assert.Contains(t, lines[1], "argo") - assert.Contains(t, lines[1], "basic") - assert.Contains(t, lines[1], "Succeeded") - } + require.NoError(t, err) + lines := strings.Split(output, "\n") + assert.Contains(t, lines[0], "NAMESPACE") + assert.Contains(t, lines[0], "NAME") + assert.Contains(t, lines[0], "STATUS") + assert.Contains(t, lines[0], "UID") + assert.Contains(t, lines[1], "argo") + assert.Contains(t, lines[1], "basic") + assert.Contains(t, lines[1], "Succeeded") }) }) s.Run("Get", func() { s.Given(). RunCli([]string{"archive", "get", string(uid)}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Name:") - assert.Contains(t, output, "Namespace:") - assert.Contains(t, output, "ServiceAccount:") - assert.Contains(t, output, "Status:") - assert.Contains(t, output, "Created:") - assert.Contains(t, output, "Started:") - assert.Contains(t, output, "Finished:") - assert.Contains(t, output, "Duration:") - } + require.NoError(t, err) + assert.Contains(t, output, "Name:") + assert.Contains(t, output, "Namespace:") + assert.Contains(t, output, "ServiceAccount:") + assert.Contains(t, output, "Status:") + assert.Contains(t, output, "Created:") + assert.Contains(t, output, "Started:") + assert.Contains(t, output, "Finished:") + assert.Contains(t, output, "Duration:") }) }) s.Run("Delete", func() { s.Given(). RunCli([]string{"archive", "delete", string(uid)}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - assert.Contains(t, output, "Archived workflow") - assert.Contains(t, output, "deleted") - } + require.NoError(t, err) + assert.Contains(t, output, "Archived workflow") + assert.Contains(t, output, "deleted") }) }) } @@ -1858,7 +1725,7 @@ func (s *CLISuite) TestArchiveLabel() { When(). CreateWorkflowTemplates(). RunCli([]string{"submit", "--from", "workflowtemplate/workflow-template-whalesay-template", "-l", "workflows.argoproj.io/test=true"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) }). WaitForWorkflow(). Then(). @@ -1868,19 +1735,17 @@ func (s *CLISuite) TestArchiveLabel() { s.Run("ListKeys", func() { s.Given(). RunCli([]string{"archive", "list-label-keys"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - lines := strings.Split(output, "\n") - assert.Contains(t, lines, "workflows.argoproj.io/test") - } + require.NoError(t, err) + lines := strings.Split(output, "\n") + assert.Contains(t, lines, "workflows.argoproj.io/test") }) }) s.Run("ListValues", func() { s.Given(). RunCli([]string{"archive", "list-label-values", "-l", "workflows.argoproj.io/test"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - lines := strings.Split(output, "\n") - assert.Contains(t, lines[0], "true") - } + require.NoError(t, err) + lines := strings.Split(output, "\n") + assert.Contains(t, lines[0], "true") }) }) } @@ -1931,28 +1796,28 @@ spec: SubmitWorkflow(). WaitForWorkflow(fixtures.ToStart). RunCli([]string{"resume", "@latest"}, func(t *testing.T, output string, err error) { - assert.Error(t, err) + require.Error(t, err) assert.Contains(t, output, "has not been set and does not have a default value") }). RunCli([]string{"node", "set", "@latest", "--output-parameter", "message=\"Hello, World!\"", "--node-field-selector", "displayName=approve"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) assert.Contains(t, output, "workflow values set") }). RunCli([]string{"node", "set", "@latest", "--output-parameter", "message=\"Hello, World!\"", "--node-field-selector", "displayName=approve"}, func(t *testing.T, output string, err error) { // Cannot double-set the same parameter - assert.Error(t, err) + require.Error(t, err) assert.Contains(t, output, "it was already set") }). RunCli([]string{"node", "set", "@latest", "--output-parameter", "message=\"Hello, World!\"", "--node-field-selector", "displayName=approve-no-vars"}, func(t *testing.T, output string, err error) { - assert.Error(t, err) + require.Error(t, err) assert.Contains(t, output, "cannot set output parameters because node is not expecting any raw parameters") }). RunCli([]string{"node", "set", "@latest", "--message", "Test message", "--node-field-selector", "displayName=approve"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) assert.Contains(t, output, "workflow values set") }). RunCli([]string{"resume", "@latest"}, func(t *testing.T, output string, err error) { - assert.NoError(t, err) + require.NoError(t, err) assert.Contains(t, output, "workflow @latest resumed") }). WaitForWorkflow(). @@ -1978,11 +1843,10 @@ func (s *CLISuite) TestPluginStruct() { SubmitWorkflow(). Then(). RunCli([]string{"get", "@latest", "-o", "yaml"}, func(t *testing.T, output string, err error) { - if assert.NoError(t, err) { - wf := wfv1.Workflow{} - assert.NoError(t, yaml.UnmarshalStrict([]byte(output), &wf)) - assert.NotNil(t, wf.Spec.Templates[0].Plugin) - } + require.NoError(t, err) + wf := wfv1.Workflow{} + require.NoError(t, yaml.UnmarshalStrict([]byte(output), &wf)) + assert.NotNil(t, wf.Spec.Templates[0].Plugin) }) } diff --git a/test/e2e/fixtures/given.go b/test/e2e/fixtures/given.go index fb6de9cf1b9a..c66861b929c2 100644 --- a/test/e2e/fixtures/given.go +++ b/test/e2e/fixtures/given.go @@ -9,6 +9,7 @@ import ( "github.com/TwiN/go-color" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "sigs.k8s.io/yaml" @@ -182,15 +183,14 @@ func (g *Given) CronWorkflow(text string) *Given { var NoError = func(t *testing.T, output string, err error) { t.Helper() - assert.NoError(t, err, output) + require.NoError(t, err, output) } var OutputRegexp = func(rx string) func(t *testing.T, output string, err error) { return func(t *testing.T, output string, err error) { t.Helper() - if assert.NoError(t, err, output) { - assert.Regexp(t, rx, output) - } + require.NoError(t, err, output) + assert.Regexp(t, rx, output) } } diff --git a/test/e2e/functional_test.go b/test/e2e/functional_test.go index 9feec785c066..edfb50a77dae 100644 --- a/test/e2e/functional_test.go +++ b/test/e2e/functional_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" apiv1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -305,10 +306,9 @@ func (s *FunctionalSuite) TestVolumeClaimTemplate() { t.FailNow() case <-ticker.C: list, err := s.KubeClient.CoreV1().PersistentVolumeClaims(fixtures.Namespace).List(context.Background(), metav1.ListOptions{}) - if assert.NoError(t, err) { - if len(list.Items) == 0 { - return - } + require.NoError(t, err) + if len(list.Items) == 0 { + return } } } diff --git a/test/e2e/retry_test.go b/test/e2e/retry_test.go index 29ac1c176ca8..0cb2fa0e3a41 100644 --- a/test/e2e/retry_test.go +++ b/test/e2e/retry_test.go @@ -153,10 +153,10 @@ spec: ctx := context.Background() podLogOptions := &apiv1.PodLogOptions{Container: "c1"} stream, err := s.KubeClient.CoreV1().Pods(ns).GetLogs(name, podLogOptions).Stream(ctx) - s.NoError(err) + s.Require().NoError(err) defer stream.Close() logBytes, err := io.ReadAll(stream) - s.NoError(err) + s.Require().NoError(err) output := string(logBytes) count := strings.Count(output, "capturing logs") s.Equal(1, count) @@ -167,10 +167,10 @@ spec: ctx := context.Background() podLogOptions := &apiv1.PodLogOptions{Container: "c2"} stream, err := s.KubeClient.CoreV1().Pods(ns).GetLogs(name, podLogOptions).Stream(ctx) - s.NoError(err) + s.Require().NoError(err) defer stream.Close() logBytes, err := io.ReadAll(stream) - s.NoError(err) + s.Require().NoError(err) output := string(logBytes) count := strings.Count(output, "capturing logs") s.Equal(0, count) @@ -181,10 +181,10 @@ spec: ctx := context.Background() podLogOptions := &apiv1.PodLogOptions{Container: "c3"} stream, err := s.KubeClient.CoreV1().Pods(ns).GetLogs(name, podLogOptions).Stream(ctx) - s.NoError(err) + s.Require().NoError(err) defer stream.Close() logBytes, err := io.ReadAll(stream) - s.NoError(err) + s.Require().NoError(err) output := string(logBytes) count := strings.Count(output, "capturing logs") s.Equal(2, count) diff --git a/workflow/artifacts/http/http_test.go b/workflow/artifacts/http/http_test.go index ea885ca9f99a..52e3502e715f 100644 --- a/workflow/artifacts/http/http_test.go +++ b/workflow/artifacts/http/http_test.go @@ -104,7 +104,7 @@ func TestSaveHTTPArtifactRedirect(t *testing.T) { // check that content is really there buf := new(bytes.Buffer) _, err = buf.ReadFrom(r.Body) - assert.NoError(t, err) + require.NoError(t, err) assert.Equal(t, content, buf.String()) w.WriteHeader(http.StatusCreated) diff --git a/workflow/executor/resource_test.go b/workflow/executor/resource_test.go index 08c652b9ba44..b5780fb60976 100644 --- a/workflow/executor/resource_test.go +++ b/workflow/executor/resource_test.go @@ -59,7 +59,7 @@ func TestResourceFlags(t *testing.T) { require.NoError(t, err) defer func() { _ = os.Remove(emptyFile.Name()) }() _, err = we.getKubectlArguments("fake", emptyFile.Name(), nil) - assert.EqualError(t, err, "Must provide at least one of flags or manifest.") + require.EqualError(t, err, "Must provide at least one of flags or manifest.") } // TestResourcePatchFlags tests whether Resource Flags