From 79555848f26c79fcf3639ecccc6aaebb412bf016 Mon Sep 17 00:00:00 2001 From: Ruslan Aliev Date: Mon, 3 Aug 2020 23:20:20 -0500 Subject: [PATCH] Fix document pull unit test in cmd TestPull unit test should not perform functional verification. The purpose of cmd unit tests should be testing proper cmd object creation, not actually run the command. Moreover, we don't have possibility to mock and track all the objects that created inside of called functions. We can only verify golden output with help or when command performs basic stuff just inside of RunE interface. Actual test of called methods performed in pkg module. Change-Id: I2ad6b76f67cbf59d798c0f2b93752b3e3b3b053d Signed-off-by: Ruslan Aliev --- cmd/document/pull_test.go | 33 ++----------------- .../document-pull-cmd-with-help.golden | 7 ++++ .../document-pull-cmd.golden | 0 3 files changed, 10 insertions(+), 30 deletions(-) create mode 100644 cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-help.golden delete mode 100644 cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd.golden diff --git a/cmd/document/pull_test.go b/cmd/document/pull_test.go index e590f8cd9..cc131168d 100644 --- a/cmd/document/pull_test.go +++ b/cmd/document/pull_test.go @@ -17,46 +17,19 @@ package document import ( "testing" - fixtures "github.com/go-git/go-git-fixtures/v4" - - "opendev.org/airship/airshipctl/pkg/config" - "opendev.org/airship/airshipctl/pkg/environment" "opendev.org/airship/airshipctl/testutil" ) -func getDummyAirshipSettings() *environment.AirshipCTLSettings { - settings := &environment.AirshipCTLSettings{Config: testutil.DummyConfig(), Create: true} - - fx := fixtures.Basic().One() - - mfst := settings.Config.Manifests["dummy_manifest"] - mfst.Repositories = map[string]*config.Repository{ - "primary": { - URLString: fx.DotGit().Root(), - CheckoutOptions: &config.RepoCheckout{ - Branch: "master", - ForceCheckout: false, - }, - Auth: &config.RepoAuth{ - Type: "http-basic", - }, - }, - } - return settings -} - func TestPull(t *testing.T) { cmdTests := []*testutil.CmdTest{ { - Name: "document-pull-cmd", - CmdLine: "", - Cmd: NewPullCommand(getDummyAirshipSettings()), + Name: "document-pull-cmd-with-help", + CmdLine: "--help", + Cmd: NewPullCommand(nil), }, } for _, tt := range cmdTests { testutil.RunTest(t, tt) } - - testutil.CleanUpGitFixtures(t) } diff --git a/cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-help.golden b/cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-help.golden new file mode 100644 index 000000000..b618d9ded --- /dev/null +++ b/cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd-with-help.golden @@ -0,0 +1,7 @@ +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.golden b/cmd/document/testdata/TestPullGoldenOutput/document-pull-cmd.golden deleted file mode 100644 index e69de29bb..000000000