Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add unit tests to plugin create/remove/enable/disable commands #878

Merged
merged 1 commit into from
Feb 15, 2018

Conversation

adshmh
Copy link
Contributor

@adshmh adshmh commented Feb 14, 2018

add tests to plugin create/remove/enable/disable commands. Part of work on #37

Signed-off-by: Arash Deshmeh adeshmeh@ca.ibm.com

- What I did
Added unit tests to several plugin commands (create/remove/enable/disable)

- How I did it
Added tests in create_test.go, remove_test.go, enable_test.go, disable_test.go

- How to verify it
Run the test suite:
make -f docker.Makefile test
- Description for the changelog
Added unit tests to plugin create/remove/enable/disable commands.

- A picture of a cute animal (not mandatory but encouraged)

@codecov-io
Copy link

codecov-io commented Feb 14, 2018

Codecov Report

Merging #878 into master will decrease coverage by 0.51%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master     #878      +/-   ##
==========================================
- Coverage   53.19%   52.67%   -0.52%     
==========================================
  Files         246      257      +11     
  Lines       16021    16403     +382     
==========================================
+ Hits         8522     8640     +118     
- Misses       6929     7190     +261     
- Partials      570      573       +3

Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just one comment to make the assertions on stdout more strict.

err = setupPluginDir(tmpDir, []byte("invalid-config-contents"))
if err != nil {
t.Fatal(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be do with (gotestyourself/fs):

tmpDir := fs.NewDir(t, "plugin-create-test",
    fs.WithDir("rootfs",
        fs.WithFile("config.json", "invalid-config-contents")))
defer tmpDir.Remove()

Just as an FYI, I think this works for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review. The gotestyourself looks very interesting (just taking a look at the above example, it reads much better than the function I wrote for these tests).

If you are OK with such a change, I can change to use gotestyourself/fs here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great, thanks!

cmd := newCreateCommand(cli)
cmd.SetArgs([]string{"plugin-foo", tmpDir})
assert.NoError(t, cmd.Execute())
assert.Equal(t, "plugin-foo", strings.TrimSpace(cli.OutBuffer().String()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should check the stdout without TrimSpace(). The trailing newline is important.

There's a few instances of this below as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I have updated the PR accordingly.

…rk on docker#37

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
@adshmh adshmh force-pushed the add-unit-tests-to-plugin-package branch from e147ce2 to 0a914da Compare February 15, 2018 11:21
Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🌵

@vdemeester vdemeester merged commit 4bc27c6 into docker:master Feb 15, 2018
@GordonTheTurtle GordonTheTurtle added this to the 18.03.0 milestone Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants