airshipctl/cmd/config/get_manifest_test.go
Vladimir Kozhukalov 0dc4ab7491 Replace PrimaryRepositoryName with PhaseRepositoryName
Change-Id: I2276a3b3ea50b8e81dd240815cd00a0a2a2af96e
Relates-To: #356
2020-10-12 15:28:27 +03:00

77 lines
1.9 KiB
Go

/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package config_test
import (
"fmt"
"testing"
cmd "opendev.org/airship/airshipctl/cmd/config"
"opendev.org/airship/airshipctl/pkg/config"
"opendev.org/airship/airshipctl/testutil"
)
func TestGetManifestConfigCmd(t *testing.T) {
settings := func() (*config.Config, error) {
return &config.Config{
Manifests: map[string]*config.Manifest{
"fooManifestConfig": getTestManifest("foo"),
"barManifestConfig": getTestManifest("bar"),
"bazManifestConfig": getTestManifest("baz"),
},
}, nil
}
noConfigSettings := func() (*config.Config, error) {
return new(config.Config), nil
}
cmdTests := []*testutil.CmdTest{
{
Name: "get-manifest",
CmdLine: "fooManifestConfig",
Cmd: cmd.NewGetManifestCommand(settings),
},
{
Name: "get-all-manifests",
CmdLine: "",
Cmd: cmd.NewGetManifestCommand(settings),
},
{
Name: "missing",
CmdLine: "manifestMissing",
Cmd: cmd.NewGetManifestCommand(settings),
Error: fmt.Errorf("missing configuration: Manifest with name 'manifestMissing'"),
},
{
Name: "no-manifests",
CmdLine: "",
Cmd: cmd.NewGetManifestCommand(noConfigSettings),
},
}
for _, tt := range cmdTests {
testutil.RunTest(t, tt)
}
}
func getTestManifest(name string) *config.Manifest {
manifests := &config.Manifest{
PhaseRepositoryName: name + "_phase_repo",
TargetPath: name + "_target_path",
}
return manifests
}