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 <raliev@mirantis.com>
This commit is contained in:
Ruslan Aliev 2020-08-03 23:20:20 -05:00
parent 645aeeb293
commit 79555848f2
3 changed files with 10 additions and 30 deletions

View File

@ -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)
}

View File

@ -0,0 +1,7 @@
Pulls documents from remote git repository
Usage:
pull [flags]
Flags:
-h, --help help for pull