-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(tests): assert.Error
-> require.Error
(other workflow/
dirs)
#13402
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we combine these PRs into one?
assert.Error
-> require.Error
(other workflow/
dirs)
173e074
to
f5a1a53
Compare
I've split these to make them easier to digest - it's otherwise a heavy but dull change to over 100 files. It's @agilgur5 and my preference to work on smaller commits. These are arbitary splits, each file could be independent or it could be a mega commit. I can pop them into one mega commit if they're not through when I get back from vacation. |
I think closer to ~150, it's quite a lot of files. Most of the changes are straight replace, but not quite all of them (in particular the |
This is part of a series of test tidies started by #13365. The aim is to enable the testifylint golangci-lint checker. This commit converts assert.Error checks into require.Error for the part of the codebase, as per #13270 (comment) In some places checks have been coaleced - in particular the pattern ```go if assert.Error() { assert.Contains(..., "message") } ``` is now ```go require.ErrorContains(..., "message") ``` Getting this wrong and missing the Contains is still valid go, so that's a mistake I may have made. Signed-off-by: Alan Clucas <alan@clucas.org>
f5a1a53
to
32f195f
Compare
Correction, after fixing what seems to be a GH rebase bug, this did end up smaller than that, ~99 on the dot I think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there could be some potential further simplifications in a few places
if !assert.NoError(t, err) { | ||
t.Fatal(err) | ||
} | ||
require.NoError(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's some inconsistent new lines in the changes here, so not sure which one you were going for; adding a new line to all or no new line for all
if !assert.True(t, ok) { | ||
t.Fatal("tmplBase is not a WorkflowTemplate") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this also be simplified?
if assert.Len(t, wf.Status.Nodes, 2) { | ||
assert.Equal(t, wfv1.NodeSucceeded, wf.Status.Nodes["1"].Phase) | ||
assert.Equal(t, wfv1.NodeRunning, wf.Status.Nodes["continue-on-failed-workflow-2"].Phase) | ||
assert.Len(t, podsToDelete, 4) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if assert.Len(t, wf.Status.Nodes, 2) { | |
assert.Equal(t, wfv1.NodeSucceeded, wf.Status.Nodes["1"].Phase) | |
assert.Equal(t, wfv1.NodeRunning, wf.Status.Nodes["continue-on-failed-workflow-2"].Phase) | |
assert.Len(t, podsToDelete, 4) | |
} | |
require.Len(t, wf.Status.Nodes, 2) | |
assert.Equal(t, wfv1.NodeSucceeded, wf.Status.Nodes["1"].Phase) | |
assert.Equal(t, wfv1.NodeRunning, wf.Status.Nodes["continue-on-failed-workflow-2"].Phase) | |
assert.Len(t, podsToDelete, 4) |
this can also be simplified as a require
if I'm not mistaken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see also my comment on the other PR: #13401 (comment)
these are not assert.Error
changes though, so may make sense as a separate PR. as it would be another indentation change though, it may make sense to consolidate for diff simplicity
@@ -602,7 +599,7 @@ func TestApplySubmitOpts(t *testing.T) { | |||
}, | |||
} | |||
err := ApplySubmitOpts(wf, &wfv1.SubmitOpts{Parameters: []string{"a=81861780812"}}) | |||
assert.NoError(t, err) | |||
require.NoError(t, err) | |||
parameters := wf.Spec.Arguments.Parameters | |||
if assert.Len(t, parameters, 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
@@ -106,16 +107,16 @@ spec: | |||
` | |||
|
|||
err = yaml.Unmarshal([]byte(cronWfInstanceIdString), &cronWf) | |||
assert.NoError(t, err) | |||
require.NoError(t, err) | |||
wf = ConvertCronWorkflowToWorkflow(&cronWf) | |||
if assert.Contains(t, wf.GetLabels(), LabelKeyControllerInstanceID) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
} | ||
require.Error(t, err) | ||
argoError, ok := err.(errors.ArgoError) | ||
if assert.True(t, ok) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above.
I also wonder if this is further simplifiable with the Error*
helpers
} | ||
require.Error(t, err) | ||
argoError, ok := err.(errors.ArgoError) | ||
if assert.True(t, ok) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
@@ -115,7 +116,7 @@ func TestLoadToStream(t *testing.T) { | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can the panic
up here also be replaced by a require.NoError
? there's a couple panic
s in the tests that seem like they should perhaps be a require.NoError
from a quick glance
@@ -62,11 +63,11 @@ func TestArtifactDriver_WithServiceKey_DownloadDirectory_Subdir(t *testing.T) { | |||
|
|||
// ensure container exists | |||
containerClient, err := driver.newAzureContainerClient() | |||
assert.NoError(t, err) | |||
require.NoError(t, err) | |||
_, err = containerClient.Create(context.Background(), nil) | |||
var responseError *azcore.ResponseError | |||
if err != nil && !(errors.As(err, &responseError) && responseError.ErrorCode == "ContainerAlreadyExists") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wondering if this might be able to be rewritten as assertions. maybe not though
Feel free to apply changes as you see fit @agilgur5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. leaving the non-error if assert.*
-> require.*
changes to a separate PR per #13402 (comment). same for the panic
-> require
etc changes
This is part of a series of test tidies started by #13365.
The aim is to enable the
testifylint
golangci-lint
checker.This commit converts
assert.Error
checks intorequire.Error
for the part of the codebase, as per #13270 (comment)In some places checks have been coalesced - in particular the pattern
is now
Getting this wrong and missing the
Contains
is still valid Go, so that's a mistake I may have made.Signed-off-by: Alan Clucas alan@clucas.org