Merge "Add utility function to be get current context target-path"

This commit is contained in:
Zuul 2020-05-01 00:36:23 +00:00 committed by Gerrit Code Review
commit 93a4449696
2 changed files with 28 additions and 0 deletions

View File

@ -675,6 +675,15 @@ func (c *Config) CurrentContextEntryPoint(phase string) (string, error) {
phase), nil
}
// CurrentContextTargetPath returns target path from current context's manifest
func (c *Config) CurrentContextTargetPath() (string, error) {
ccm, err := c.CurrentContextManifest()
if err != nil {
return "", err
}
return ccm.TargetPath, nil
}
func (c *Config) CurrentContextClusterType() (string, error) {
context, err := c.GetCurrentContext()
if err != nil {

View File

@ -486,6 +486,25 @@ func TestCurrentContextManifest(t *testing.T) {
assert.Equal(t, conf.Manifests[defaultString], manifest)
}
func TestCurrentTargetPath(t *testing.T) {
conf, cleanup := testutil.InitConfig(t)
defer cleanup(t)
clusterName := "def"
manifest, err := conf.CurrentContextManifest()
require.Error(t, err)
assert.Nil(t, manifest)
conf.CurrentContext = currentContextName
conf.Contexts[currentContextName].Manifest = defaultString
conf.Contexts[currentContextName].KubeContext().Cluster = clusterName
targetPath, err := conf.CurrentContextTargetPath()
require.NoError(t, err)
assert.Equal(t, conf.Manifests[defaultString].TargetPath, targetPath)
}
func TestCurrentContextEntryPoint(t *testing.T) {
conf, cleanup := testutil.InitConfig(t)
defer cleanup(t)