091fa09a23
This commit adds the utility testing function TempDir, which provides a tester with a temporary directory as well as a means of cleaning up that directory. The new function is implemented everywhere that makes sense throughout the code base. This also cleans up the directories left behind by go-git's testing fixtures. Some light refactoring was also performed in this change. Change-Id: I754484934660487140f57671bacb5463cf669e3e
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package document
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
fixtures "gopkg.in/src-d/go-git-fixtures.v3"
|
|
|
|
"opendev.org/airship/airshipctl/pkg/config"
|
|
"opendev.org/airship/airshipctl/pkg/environment"
|
|
|
|
"opendev.org/airship/airshipctl/testutil"
|
|
)
|
|
|
|
func getDummyAirshipSettings(t *testing.T) *environment.AirshipCTLSettings {
|
|
settings := new(environment.AirshipCTLSettings)
|
|
conf := config.DummyConfig()
|
|
mfst := conf.Manifests["dummy_manifest"]
|
|
|
|
err := fixtures.Init()
|
|
require.NoError(t, err)
|
|
|
|
fx := fixtures.Basic().One()
|
|
|
|
mfst.Repository = &config.Repository{
|
|
URLString: fx.DotGit().Root(),
|
|
CheckoutOptions: &config.RepoCheckout{
|
|
Branch: "master",
|
|
ForceCheckout: false,
|
|
},
|
|
Auth: &config.RepoAuth{
|
|
Type: "http-basic",
|
|
},
|
|
}
|
|
settings.SetConfig(conf)
|
|
return settings
|
|
}
|
|
|
|
func TestPull(t *testing.T) {
|
|
cmdTests := []*testutil.CmdTest{
|
|
{
|
|
Name: "document-pull-cmd-with-defaults",
|
|
CmdLine: "",
|
|
Cmd: NewDocumentPullCommand(getDummyAirshipSettings(t)),
|
|
},
|
|
{
|
|
Name: "document-pull-cmd-with-help",
|
|
CmdLine: "--help",
|
|
Cmd: NewDocumentPullCommand(nil),
|
|
},
|
|
}
|
|
|
|
for _, tt := range cmdTests {
|
|
testutil.RunTest(t, tt)
|
|
}
|
|
|
|
testutil.CleanUpGitFixtures(t)
|
|
}
|