Add utility function to be get current context target-path

Change-Id: I9ec841ab695526736b7bdfecfa911b3cb2204b2c
This commit is contained in:
Kostiantyn Kalynovskyi 2020-04-27 18:47:52 -05:00 committed by Kostyantyn Kalynovskyi
parent b57c1a2d15
commit 081721816e
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)