Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Template formatted output for ps & inspect #518

Merged

Conversation

darkowlzz
Copy link
Contributor

@darkowlzz darkowlzz commented Feb 4, 2020

Adds new flag --template (-t) for Go template formatted output in inspect and ps subcommands.
Since ps command already has a -f flag for --filter, this uses -t for template formatted output.

Adds golden files based tests for Inspect() and Ps() to verify the results.

@darkowlzz darkowlzz force-pushed the formatted-output-ps-inspect branch 3 times, most recently from 0ab526b to 1eff553 Compare February 10, 2020 09:16
@darkowlzz
Copy link
Contributor Author

Updated the commits to replace separate flags for updating the test golden files with a single -update flag for all the test updates.

@stealthybox
Copy link
Contributor

stealthybox commented Feb 24, 2020

The template format works great, but the golden-file tests are flaky because the output order is not sorted and stable.

Running with -count 1 will disable test caching.
Try -count 10 as well:

go test ./cmd/ignite/run -count 10 -run TestPs

Perhaps we should consider sorting by name or ID before outputting the table.
We don't need to fix this in this PR.

Also, you may find it helpful to change the test runner to output strings:

t.Errorf("expected output to be:\n%v\ngot output:\n%v", string(wantOutput), string(buf.Bytes()))

This adds a new flag to `ignite ps` command `--template` to render the
ps output based on passed Go template.

Adds test for Ps().
This adds a new flag to `ignite inspect` command `--template` to render
the inspect output based on passed Go template.

Adds test for Inspect().
Use a slice for the list of existing VMs to retain the order of the VMs
created in the test.
Update the test runner to print strings of the compared outputs, instead
of bytes.
@darkowlzz
Copy link
Contributor Author

Thanks for catching the issue.
Rebased the changes on latest master.
Changed the list of existing VMs to use a slice of runtime.ObjectMeta, instead of a map of VM name and ID, and tested it with -count=10. Seems to work reliably now.

@stealthybox stealthybox merged commit 812e22b into weaveworks:master Mar 2, 2020
@luxas luxas added this to the v0.7.0 milestone Jun 2, 2020
@darkowlzz darkowlzz deleted the formatted-output-ps-inspect branch July 19, 2020 12:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants