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

Tink-cli unit tests #366

Merged
merged 1 commit into from
Dec 3, 2020
Merged

Conversation

CarlosOVillanueva
Copy link

Signed-off-by: [email protected] [email protected]

Description

Unit tests to validate functionality of tink-cli. These tests do not require external components to be live. They simply test to see if the sub-functions exists and use the help argument to return the description of the command.

Why is this needed

To ensure commands persist between versions.

Fixes: #

How Has This Been Tested?

Run go test -v from within cmd/tink-cli/cmd

agrant@provisioner:/vagrant/cmd/tink-cli/cmd$ go test -v
=== RUN   Test_docsCmd
=== RUN   Test_docsCmd/NoArgs
Error: accepts 1 arg(s), received 0
Usage:
  tink-cli docs [markdown|man] [flags]

Flags:
  -h, --help          help for docs
  -p, --path string   Path where documentation will be generated

=== RUN   Test_docsCmd/Help
=== RUN   Test_docsCmd/Markdown
=== RUN   Test_docsCmd/Man
=== RUN   Test_docsCmd/BadFormat
Error: invalid argument "invalid" for "tink-cli docs"
Usage:
  tink-cli docs [markdown|man] [flags]

Flags:
  -h, --help          help for docs
  -p, --path string   Path where documentation will be generated

--- PASS: Test_docsCmd (0.00s)
    --- PASS: Test_docsCmd/NoArgs (0.00s)
    --- PASS: Test_docsCmd/Help (0.00s)
    --- PASS: Test_docsCmd/Markdown (0.00s)
    --- PASS: Test_docsCmd/Man (0.00s)
    --- PASS: Test_docsCmd/BadFormat (0.00s)
=== RUN   Test_hardwareCmd
=== RUN   Test_hardwareCmd/NoArgs
tink hardware client

Usage:
  tink-cli hardware [command]

Examples:
tink hardware [command]

Available Commands:
  delete      delete hardware by id
  id          get hardware by id
  ip          get hardware by any associated ip
  list        list all known hardware
  mac         get hardware by any associated mac
  push        push new hardware to tink
  watch       register to watch an id for any changes

Flags:
  -h, --help   help for hardware

Use "tink-cli hardware [command] --help" for more information about a command.
=== RUN   Test_hardwareCmd/ID
=== RUN   Test_hardwareCmd/List
=== RUN   Test_hardwareCmd/IP
=== RUN   Test_hardwareCmd/MAC
=== RUN   Test_hardwareCmd/Delete
=== RUN   Test_hardwareCmd/Watch
=== RUN   Test_hardwareCmd/Push
--- PASS: Test_hardwareCmd (0.00s)
    --- PASS: Test_hardwareCmd/NoArgs (0.00s)
    --- PASS: Test_hardwareCmd/ID (0.00s)
    --- PASS: Test_hardwareCmd/List (0.00s)
    --- PASS: Test_hardwareCmd/IP (0.00s)
    --- PASS: Test_hardwareCmd/MAC (0.00s)
    --- PASS: Test_hardwareCmd/Delete (0.00s)
    --- PASS: Test_hardwareCmd/Watch (0.00s)
    --- PASS: Test_hardwareCmd/Push (0.00s)
=== RUN   Test_templateCmd
=== RUN   Test_templateCmd/NoArgs
tink template client

Usage:
  tink-cli template [command]

Examples:
tink template [command]

Available Commands:
  create      create a workflow template 
  delete      delete a template
  get         get a template
  list        list all saved templates
  update      update a template

Flags:
  -h, --help   help for template

Use "tink-cli template [command] --help" for more information about a command.
=== RUN   Test_templateCmd/List
=== RUN   Test_templateCmd/Create
=== RUN   Test_templateCmd/Delete
=== RUN   Test_templateCmd/Get
=== RUN   Test_templateCmd/Update
--- PASS: Test_templateCmd (0.00s)
    --- PASS: Test_templateCmd/NoArgs (0.00s)
    --- PASS: Test_templateCmd/List (0.00s)
    --- PASS: Test_templateCmd/Create (0.00s)
    --- PASS: Test_templateCmd/Delete (0.00s)
    --- PASS: Test_templateCmd/Get (0.00s)
    --- PASS: Test_templateCmd/Update (0.00s)
=== RUN   Test_workflowCmd
=== RUN   Test_workflowCmd/NoArgs
tink workflow client

Usage:
  tink-cli workflow [command]

Examples:
tink workflow [command]

Available Commands:
  create      create a workflow
  data        get workflow data
  delete      delete a workflow
  events      show all events for a workflow
  get         get a workflow
  list        list all workflows
  state       get the current workflow state

Flags:
  -h, --help   help for workflow

Use "tink-cli workflow [command] --help" for more information about a command.
=== RUN   Test_workflowCmd/List
=== RUN   Test_workflowCmd/Create
=== RUN   Test_workflowCmd/Data
=== RUN   Test_workflowCmd/Delete
=== RUN   Test_workflowCmd/Events
=== RUN   Test_workflowCmd/Get
=== RUN   Test_workflowCmd/State
--- PASS: Test_workflowCmd (0.00s)
    --- PASS: Test_workflowCmd/NoArgs (0.00s)
    --- PASS: Test_workflowCmd/List (0.00s)
    --- PASS: Test_workflowCmd/Create (0.00s)
    --- PASS: Test_workflowCmd/Data (0.00s)
    --- PASS: Test_workflowCmd/Delete (0.00s)
    --- PASS: Test_workflowCmd/Events (0.00s)
    --- PASS: Test_workflowCmd/Get (0.00s)
    --- PASS: Test_workflowCmd/State (0.00s)
PASS
ok      github.com/tinkerbell/tink/cmd/tink-cli/cmd     0.013s

How are existing users impacted? What migration steps/scripts do we need?

No user impact

Checklist:

I have:

  • updated the documentation and/or roadmap (if required)
  • added unit or e2e tests
  • provided instructions on how to upgrade

@CarlosOVillanueva CarlosOVillanueva changed the title added tink-cli unit tests Tink-cli unit tests Nov 13, 2020
@codecov
Copy link

codecov bot commented Nov 13, 2020

Codecov Report

Merging #366 (c615c34) into master (a2d22a0) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #366   +/-   ##
=======================================
  Coverage   24.74%   24.74%           
=======================================
  Files          14       14           
  Lines        1277     1277           
=======================================
  Hits          316      316           
  Misses        940      940           
  Partials       21       21           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a2d22a0...c615c34. Read the comment docs.

@gianarb gianarb requested review from mmlb and displague November 13, 2020 20:10
@displague
Copy link
Member

displague commented Nov 16, 2020

Thanks for these coverage improvements, @CarlosOVillanueva!

I think the much more interesting parts of this PR are the changes to GetTemplate which appear to fix the name returned by GetTemplate and now include the ID of the template in the response.

I'm curious about what benefit this brings. I'm a little detached from this code at the moment, but it looks like the id and name being sent in as required parameters in the maps[string]string are now being returned back to the caller as additional function results. I may be missing something here because it's not apparent to me why the name was ever being returned back in this fashion, and now we are also returning id.

If these changes were to appease the tests, I think we should update the tests instead. Affecting the API of the client will have more downstream ramifications as we add clients (tink-cli, terraform, crossplane, etc).

Can you offer some explanation for these changes, as it isn't obvious to me?

@gianarb
Copy link
Contributor

gianarb commented Dec 3, 2020

@CarlosOVillanueva do you mind rebasing this PR and have a look at the comment @displague left?

Thanks a lot

@CarlosOVillanueva
Copy link
Author

Thanks for these coverage improvements, @CarlosOVillanueva!

I think the much more interesting parts of this PR are the changes to GetTemplate which appear to fix the name returned by GetTemplate and now include the ID of the template in the response.

I'm curious about what benefit this brings. I'm a little detached from this code at the moment, but it looks like the id and name being sent in as required parameters in the maps[string]string are now being returned back to the caller as additional function results. I may be missing something here because it's not apparent to me why the name was ever being returned back in this fashion, and now we are also returning id.

If these changes were to appease the tests, I think we should update the tests instead. Affecting the API of the client will have more downstream ramifications as we add clients (tink-cli, terraform, crossplane, etc).

Can you offer some explanation for these changes, as it isn't obvious to me?

Let me see what happened there. I suspect that was the result of a merge and me not rebasing the project. I'll fix and resubmit.

@gianarb gianarb added the ready-to-merge Signal to Mergify to merge the PR. label Dec 3, 2020
@gianarb gianarb requested review from displague and removed request for displague and mmlb December 3, 2020 18:11
Copy link
Contributor

@gianarb gianarb left a comment

Choose a reason for hiding this comment

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

This is testing only helps commands. It is a bit weird as an assertion but it is a good starting point I presume

Copy link
Member

@displague displague 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, @CarlosOVillanueva !

@mergify mergify bot merged commit 86057d3 into tinkerbell:master Dec 3, 2020
@mmlb mmlb removed the ready-to-merge Signal to Mergify to merge the PR. label Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants