-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Replace testify assertions with gotestyourself/assert #879
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,8 +13,9 @@ import ( | |
| // Import builders to get the builder function as package function | ||
| . "github.com/docker/cli/internal/test/builders" | ||
| "github.com/docker/cli/internal/test/testutil" | ||
| "github.com/gotestyourself/gotestyourself/assert" | ||
| is "github.com/gotestyourself/gotestyourself/assert/cmp" | ||
| "github.com/gotestyourself/gotestyourself/golden" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestConfigListErrors(t *testing.T) { | ||
|
|
@@ -72,7 +73,7 @@ func TestConfigList(t *testing.T) { | |
| }, | ||
| }) | ||
| cmd := newConfigListCommand(cli) | ||
| assert.NoError(t, cmd.Execute()) | ||
| assert.Check(t, cmd.Execute()) | ||
| golden.Assert(t, cli.OutBuffer().String(), "config-list-sort.golden") | ||
| } | ||
|
|
||
|
|
@@ -89,7 +90,7 @@ func TestConfigListWithQuietOption(t *testing.T) { | |
| }) | ||
| cmd := newConfigListCommand(cli) | ||
| cmd.Flags().Set("quiet", "true") | ||
| assert.NoError(t, cmd.Execute()) | ||
| assert.Check(t, cmd.Execute()) | ||
| golden.Assert(t, cli.OutBuffer().String(), "config-list-with-quiet-option.golden") | ||
| } | ||
|
|
||
|
|
@@ -108,7 +109,7 @@ func TestConfigListWithConfigFormat(t *testing.T) { | |
| ConfigFormat: "{{ .Name }} {{ .Labels }}", | ||
| }) | ||
| cmd := newConfigListCommand(cli) | ||
| assert.NoError(t, cmd.Execute()) | ||
| assert.Check(t, cmd.Execute()) | ||
| golden.Assert(t, cli.OutBuffer().String(), "config-list-with-config-format.golden") | ||
| } | ||
|
|
||
|
|
@@ -125,15 +126,15 @@ func TestConfigListWithFormat(t *testing.T) { | |
| }) | ||
| cmd := newConfigListCommand(cli) | ||
| cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}") | ||
| assert.NoError(t, cmd.Execute()) | ||
| assert.Check(t, cmd.Execute()) | ||
| golden.Assert(t, cli.OutBuffer().String(), "config-list-with-format.golden") | ||
| } | ||
|
|
||
| func TestConfigListWithFilter(t *testing.T) { | ||
| cli := test.NewFakeCli(&fakeClient{ | ||
| configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) { | ||
| assert.Equal(t, "foo", options.Filters.Get("name")[0]) | ||
| assert.Equal(t, "lbl1=Label-bar", options.Filters.Get("label")[0]) | ||
| assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0])) | ||
| assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0])) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I find assert.Equal(t, "lbl1=Label-bar", options.Filters.Get("label")[0])vs assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0]))The last one I have to read until position 20 (with indentation, position 32) to see what kind of check is done, and the Basically Was this a deliberate design choice in gotestyourself?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, gotestyourself/gotest.tools#49 (comment). I think we should add more
The convenience assertions added to the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe then you nay use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you could use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gotestyourself/gotest.tools#71 adds some more top level asserts for handling errors.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dnephin looking good! I think we should move this forward (sorry for stalling this). Looks like this'll need a massive rebase (or was it all done automated?)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was mostly automated, so it should be easy to just re-run that automation. |
||
| return []swarm.Config{ | ||
| *Config(ConfigID("ID-foo"), | ||
| ConfigName("foo"), | ||
|
|
@@ -153,6 +154,6 @@ func TestConfigListWithFilter(t *testing.T) { | |
| cmd := newConfigListCommand(cli) | ||
| cmd.Flags().Set("filter", "name=foo") | ||
| cmd.Flags().Set("filter", "label=lbl1=Label-bar") | ||
| assert.NoError(t, cmd.Execute()) | ||
| assert.Check(t, cmd.Execute()) | ||
| golden.Assert(t, cli.OutBuffer().String(), "config-list-with-filter.golden") | ||
| } | ||
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.
Is it possible to automate changing these to
assert.Error()(gotestyourself/gotest.tools#71), or do you want to keep that for a follow-up ?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's possible to automate the change, but it's not the same as gotestyourself/gotest.tools#71.
The current automated migration preserves behaviour, so
testify/require->Assert,testify/assert->Check.I can write another migration that converts specific checks to the canonical
Assert, but that is a change in behaviour (Fail -> FailNow), so I'd like to do that in a separate PR so that we can more carefully review the change.