From 95a768e366af522a02930587262bc70a9b1cb976 Mon Sep 17 00:00:00 2001 From: Ian Howell Date: Tue, 28 Apr 2020 13:45:27 -0500 Subject: [PATCH] Increase code coverage This adds coverage to: * NewDocumentCommand * NewBaremetalCommand Change-Id: I7ece84cd36a4df07dc4c2e7437175484ced9b802 --- cmd/baremetal/baremetal_test.go | 9 ++++- .../{baremetal_isogen.go => isogen.go} | 0 ...emetal_remotedirect.go => remotedirect.go} | 0 ...lden => baremetal-isogen-with-help.golden} | 0 ...> baremetal-remotedirect-with-help.golden} | 0 .../baremetal-with-help.golden | 14 +++++++ cmd/document/document_test.go | 15 ++++++++ cmd/document/plugin_test.go | 5 --- cmd/document/pull_test.go | 7 +--- .../document-plugin-with-help.golden} | 0 .../document-pull-with-help.golden | 37 +++++++++++++++++++ .../document-with-help.golden | 15 ++++++++ .../document-pull-cmd-with-help.golden | 7 ---- ...faults.golden => document-pull-cmd.golden} | 0 14 files changed, 89 insertions(+), 20 deletions(-) rename cmd/baremetal/{baremetal_isogen.go => isogen.go} (100%) rename cmd/baremetal/{baremetal_remotedirect.go => remotedirect.go} (100%) rename cmd/baremetal/testdata/TestBaremetalGoldenOutput/{isogen.golden => baremetal-isogen-with-help.golden} (100%) rename cmd/baremetal/testdata/TestBaremetalGoldenOutput/{remotedirect.golden => baremetal-remotedirect-with-help.golden} (100%) create mode 100644 cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-with-help.golden rename cmd/document/testdata/{TestPluginGoldenOutput/document-plugin-cmd-with-help.golden => TestDocumentGoldenOutput/document-plugin-with-help.golden} (100%) create mode 100644 cmd/document/testdata/TestDocumentGoldenOutput/document-pull-with-help.golden create mode 100644 cmd/document/testdata/TestDocumentGoldenOutput/document-with-help.golden delete mode 100644 cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-help.golden rename cmd/document/testdata/TestPullGoldenOutput/{document-pull-cmd-with-defaults.golden => document-pull-cmd.golden} (100%) diff --git a/cmd/baremetal/baremetal_test.go b/cmd/baremetal/baremetal_test.go index 3e8a7d315..9753172d0 100644 --- a/cmd/baremetal/baremetal_test.go +++ b/cmd/baremetal/baremetal_test.go @@ -24,12 +24,17 @@ import ( func TestBaremetal(t *testing.T) { tests := []*testutil.CmdTest{ { - Name: "isogen", + Name: "baremetal-with-help", + CmdLine: "-h", + Cmd: baremetal.NewBaremetalCommand(nil), + }, + { + Name: "baremetal-isogen-with-help", CmdLine: "-h", Cmd: baremetal.NewISOGenCommand(nil), }, { - Name: "remotedirect", + Name: "baremetal-remotedirect-with-help", CmdLine: "-h", Cmd: baremetal.NewRemoteDirectCommand(nil), }, diff --git a/cmd/baremetal/baremetal_isogen.go b/cmd/baremetal/isogen.go similarity index 100% rename from cmd/baremetal/baremetal_isogen.go rename to cmd/baremetal/isogen.go diff --git a/cmd/baremetal/baremetal_remotedirect.go b/cmd/baremetal/remotedirect.go similarity index 100% rename from cmd/baremetal/baremetal_remotedirect.go rename to cmd/baremetal/remotedirect.go diff --git a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/isogen.golden b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-isogen-with-help.golden similarity index 100% rename from cmd/baremetal/testdata/TestBaremetalGoldenOutput/isogen.golden rename to cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-isogen-with-help.golden diff --git a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/remotedirect.golden b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-remotedirect-with-help.golden similarity index 100% rename from cmd/baremetal/testdata/TestBaremetalGoldenOutput/remotedirect.golden rename to cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-remotedirect-with-help.golden diff --git a/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-with-help.golden b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-with-help.golden new file mode 100644 index 000000000..5d05060d9 --- /dev/null +++ b/cmd/baremetal/testdata/TestBaremetalGoldenOutput/baremetal-with-help.golden @@ -0,0 +1,14 @@ +Perform actions on baremetal hosts + +Usage: + baremetal [command] + +Available Commands: + help Help about any command + isogen Generate baremetal host ISO image + remotedirect Bootstrap the ephemeral host + +Flags: + -h, --help help for baremetal + +Use "baremetal [command] --help" for more information about a command. diff --git a/cmd/document/document_test.go b/cmd/document/document_test.go index 572ac5ed0..da61bf386 100644 --- a/cmd/document/document_test.go +++ b/cmd/document/document_test.go @@ -23,11 +23,26 @@ import ( func TestDocument(t *testing.T) { tests := []*testutil.CmdTest{ + { + Name: "document-with-help", + CmdLine: "-h", + Cmd: document.NewDocumentCommand(nil), + }, { Name: "document-render-with-help", CmdLine: "-h", Cmd: document.NewRenderCommand(nil), }, + { + Name: "document-plugin-with-help", + CmdLine: "-h", + Cmd: document.NewPluginCommand(nil), + }, + { + Name: "document-pull-with-help", + CmdLine: "-h", + Cmd: document.NewPluginCommand(nil), + }, } for _, tt := range tests { testutil.RunTest(t, tt) diff --git a/cmd/document/plugin_test.go b/cmd/document/plugin_test.go index 7974d0cb7..540e54f34 100644 --- a/cmd/document/plugin_test.go +++ b/cmd/document/plugin_test.go @@ -23,11 +23,6 @@ import ( func TestPlugin(t *testing.T) { cmdTests := []*testutil.CmdTest{ - { - Name: "document-plugin-cmd-with-help", - CmdLine: "--help", - Cmd: NewPluginCommand(nil), - }, { Name: "document-plugin-cmd-with-empty-args", CmdLine: "", diff --git a/cmd/document/pull_test.go b/cmd/document/pull_test.go index b02e0bfaf..58d48f070 100644 --- a/cmd/document/pull_test.go +++ b/cmd/document/pull_test.go @@ -48,15 +48,10 @@ func getDummyAirshipSettings() *environment.AirshipCTLSettings { func TestPull(t *testing.T) { cmdTests := []*testutil.CmdTest{ { - Name: "document-pull-cmd-with-defaults", + Name: "document-pull-cmd", CmdLine: "", Cmd: NewPullCommand(getDummyAirshipSettings()), }, - { - Name: "document-pull-cmd-with-help", - CmdLine: "--help", - Cmd: NewPullCommand(nil), - }, } for _, tt := range cmdTests { diff --git a/cmd/document/testdata/TestPluginGoldenOutput/document-plugin-cmd-with-help.golden b/cmd/document/testdata/TestDocumentGoldenOutput/document-plugin-with-help.golden similarity index 100% rename from cmd/document/testdata/TestPluginGoldenOutput/document-plugin-cmd-with-help.golden rename to cmd/document/testdata/TestDocumentGoldenOutput/document-plugin-with-help.golden diff --git a/cmd/document/testdata/TestDocumentGoldenOutput/document-pull-with-help.golden b/cmd/document/testdata/TestDocumentGoldenOutput/document-pull-with-help.golden new file mode 100644 index 000000000..b10d1154b --- /dev/null +++ b/cmd/document/testdata/TestDocumentGoldenOutput/document-pull-with-help.golden @@ -0,0 +1,37 @@ +This command is meant to be used as a kustomize exec plugin. + +The command reads the configuration file CONFIG passed as a first argument and +determines a particular plugin to execute. Additional arguments may be passed +to this command and can be used by the particular plugin. + +CONFIG must be a structured kubernetes manifest (i.e. resource) and must have +'apiVersion' and 'kind' keys. If the appropriate plugin was not found, the +command returns an error. + +Usage: + plugin CONFIG [ARGS] [flags] + +Examples: + +# Perform a replacement on a deployment. Prior to running this command, +# the file '/tmp/replacement.yaml' should be created as follows: +--- +apiVersion: airshipit.org/v1alpha1 +kind: ReplacementTransformer +metadata: + name: notImportantHere +replacements: +- source: + value: nginx:newtag + target: + objref: + kind: Deployment + fieldrefs: + - spec.template.spec.containers[name=nginx-latest].image + +# The replacement can then be performed. Output defaults to stdout. +airshipctl document plugin /tmp/replacement.yaml + + +Flags: + -h, --help help for plugin diff --git a/cmd/document/testdata/TestDocumentGoldenOutput/document-with-help.golden b/cmd/document/testdata/TestDocumentGoldenOutput/document-with-help.golden new file mode 100644 index 000000000..a0b6c4a38 --- /dev/null +++ b/cmd/document/testdata/TestDocumentGoldenOutput/document-with-help.golden @@ -0,0 +1,15 @@ +Manage deployment documents + +Usage: + document [command] + +Available Commands: + help Help about any command + plugin Run as a kustomize exec plugin + pull Pulls documents from remote git repository + render Render documents from model + +Flags: + -h, --help help for document + +Use "document [command] --help" for more information about a command. diff --git a/cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-help.golden b/cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-help.golden deleted file mode 100644 index b618d9ded..000000000 --- a/cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-help.golden +++ /dev/null @@ -1,7 +0,0 @@ -Pulls documents from remote git repository - -Usage: - pull [flags] - -Flags: - -h, --help help for pull diff --git a/cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-defaults.golden b/cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd.golden similarity index 100% rename from cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-defaults.golden rename to cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd.golden