From 2769c62c8acf2cbc3ca0afbe89c29d4d34b7516c Mon Sep 17 00:00:00 2001
From: Sirajudeen <sirajudeen.yasin@gmail.com>
Date: Thu, 24 Sep 2020 14:28:30 +0000
Subject: [PATCH] Update metadataPath using set-manifest in cli

* Added metatada-path as a flag to set-manifest

Change-Id: Id26f20c4a6350b4aae34da850bbfcab42cbe9f21
---
 cmd/config/set_manifest.go                    |  8 +++-
 cmd/config/set_manifest_test.go               | 47 +++++++++++--------
 ...onfig-cmd-set-manifest-too-few-args.golden | 21 +++++----
 ...nfig-cmd-set-manifest-too-many-args.golden | 21 +++++----
 .../config-cmd-set-manifest-with-help.golden  | 21 +++++----
 pkg/config/config.go                          |  3 ++
 pkg/config/options.go                         | 23 ++++-----
 7 files changed, 83 insertions(+), 61 deletions(-)

diff --git a/cmd/config/set_manifest.go b/cmd/config/set_manifest.go
index 1975377a9..88075242d 100644
--- a/cmd/config/set_manifest.go
+++ b/cmd/config/set_manifest.go
@@ -145,5 +145,11 @@ func addSetManifestFlags(o *config.ManifestOptions, cmd *cobra.Command) {
 		&o.TargetPath,
 		"target-path",
 		"",
-		"the target path for to be set for this manifest")
+		"the target path to be set for this manifest")
+
+	flags.StringVar(
+		&o.MetadataPath,
+		"metadata-path",
+		"",
+		"the metadata path to be set for this manifest")
 }
diff --git a/cmd/config/set_manifest_test.go b/cmd/config/set_manifest_test.go
index 5d7c4d9f1..c3076400c 100644
--- a/cmd/config/set_manifest_test.go
+++ b/cmd/config/set_manifest_test.go
@@ -28,21 +28,24 @@ import (
 )
 
 const (
-	mName       = "dummymanifest"
-	mRepoName   = "treasuremap"
-	mURL        = "https://github.com/airshipit/treasuremap"
-	mBranch     = "master"
-	mSubPath    = "manifests/test-site"
-	mTargetPath = "/tmp/airship"
+	mName         = "dummymanifest"
+	mRepoName     = "treasuremap"
+	mURL          = "https://github.com/airshipit/treasuremap"
+	mBranch       = "master"
+	mSubPath      = "manifests/test-site"
+	mTargetPath   = "/tmp/airship"
+	mMetadataPath = "manifests/metadata.yaml"
 
-	testTargetPath = "/tmp/e2e"
+	testTargetPath   = "/tmp/e2e"
+	testMetadataPath = "manifests/docker_metadata.yaml"
 )
 
 type setManifestTest struct {
-	inputConfig        *config.Config
-	cmdTest            *testutil.CmdTest
-	manifestName       string
-	manifestTargetPath string
+	inputConfig          *config.Config
+	cmdTest              *testutil.CmdTest
+	manifestName         string
+	manifestTargetPath   string
+	manifestMetadataPath string
 }
 
 func TestConfigSetManifest(t *testing.T) {
@@ -81,6 +84,7 @@ func TestSetManifest(t *testing.T) {
 		flags        []string
 		givenConfig  *config.Config
 		targetPath   string
+		metadataPath string
 	}{
 		{
 			testName:     "set-manifest",
@@ -92,18 +96,22 @@ func TestSetManifest(t *testing.T) {
 				"--primary",
 				"--sub-path " + mSubPath,
 				"--target-path " + mTargetPath,
+				"--metadata-path " + mMetadataPath,
 			},
-			givenConfig: given,
-			targetPath:  mTargetPath,
+			givenConfig:  given,
+			targetPath:   mTargetPath,
+			metadataPath: mMetadataPath,
 		},
 		{
 			testName:     "modify-manifest",
 			manifestName: mName,
 			flags: []string{
 				"--target-path " + testTargetPath,
+				"--metadata-path " + testMetadataPath,
 			},
-			givenConfig: given,
-			targetPath:  testTargetPath,
+			givenConfig:  given,
+			targetPath:   testTargetPath,
+			metadataPath: mMetadataPath,
 		},
 	}
 
@@ -114,10 +122,11 @@ func TestSetManifest(t *testing.T) {
 			CmdLine: fmt.Sprintf("%s %s", tt.manifestName, strings.Join(tt.flags, " ")),
 		}
 		test := setManifestTest{
-			inputConfig:        tt.givenConfig,
-			cmdTest:            cmd,
-			manifestName:       tt.manifestName,
-			manifestTargetPath: tt.targetPath,
+			inputConfig:          tt.givenConfig,
+			cmdTest:              cmd,
+			manifestName:         tt.manifestName,
+			manifestTargetPath:   tt.targetPath,
+			manifestMetadataPath: tt.metadataPath,
 		}
 		test.run(t)
 	}
diff --git a/cmd/config/testdata/TestConfigSetManifestGoldenOutput/config-cmd-set-manifest-too-few-args.golden b/cmd/config/testdata/TestConfigSetManifestGoldenOutput/config-cmd-set-manifest-too-few-args.golden
index d50687210..51780b6b3 100644
--- a/cmd/config/testdata/TestConfigSetManifestGoldenOutput/config-cmd-set-manifest-too-few-args.golden
+++ b/cmd/config/testdata/TestConfigSetManifestGoldenOutput/config-cmd-set-manifest-too-few-args.golden
@@ -28,14 +28,15 @@ airshipctl config set-manifest e2e \
 
 
 Flags:
-      --branch string        the branch to be associated with repository in this manifest
-      --commithash string    the commit hash to be associated with repository in this manifest
-      --force                if set, enable force checkout in repository with this manifest
-  -h, --help                 help for set-manifest
-      --primary              if set, enable this repository as primary repository to be used with this manifest
-      --repo string          the name of the repository to be associated with this manifest
-      --sub-path string      the sub path to be set for this manifest
-      --tag string           the tag to be associated with repository in this manifest
-      --target-path string   the target path for to be set for this manifest
-      --url string           the repository url to be associated with this manifest
+      --branch string          the branch to be associated with repository in this manifest
+      --commithash string      the commit hash to be associated with repository in this manifest
+      --force                  if set, enable force checkout in repository with this manifest
+  -h, --help                   help for set-manifest
+      --metadata-path string   the metadata path to be set for this manifest
+      --primary                if set, enable this repository as primary repository to be used with this manifest
+      --repo string            the name of the repository to be associated with this manifest
+      --sub-path string        the sub path to be set for this manifest
+      --tag string             the tag to be associated with repository in this manifest
+      --target-path string     the target path to be set for this manifest
+      --url string             the repository url to be associated with this manifest
 
diff --git a/cmd/config/testdata/TestConfigSetManifestGoldenOutput/config-cmd-set-manifest-too-many-args.golden b/cmd/config/testdata/TestConfigSetManifestGoldenOutput/config-cmd-set-manifest-too-many-args.golden
index 5f91c08bf..14a6ad300 100644
--- a/cmd/config/testdata/TestConfigSetManifestGoldenOutput/config-cmd-set-manifest-too-many-args.golden
+++ b/cmd/config/testdata/TestConfigSetManifestGoldenOutput/config-cmd-set-manifest-too-many-args.golden
@@ -28,14 +28,15 @@ airshipctl config set-manifest e2e \
 
 
 Flags:
-      --branch string        the branch to be associated with repository in this manifest
-      --commithash string    the commit hash to be associated with repository in this manifest
-      --force                if set, enable force checkout in repository with this manifest
-  -h, --help                 help for set-manifest
-      --primary              if set, enable this repository as primary repository to be used with this manifest
-      --repo string          the name of the repository to be associated with this manifest
-      --sub-path string      the sub path to be set for this manifest
-      --tag string           the tag to be associated with repository in this manifest
-      --target-path string   the target path for to be set for this manifest
-      --url string           the repository url to be associated with this manifest
+      --branch string          the branch to be associated with repository in this manifest
+      --commithash string      the commit hash to be associated with repository in this manifest
+      --force                  if set, enable force checkout in repository with this manifest
+  -h, --help                   help for set-manifest
+      --metadata-path string   the metadata path to be set for this manifest
+      --primary                if set, enable this repository as primary repository to be used with this manifest
+      --repo string            the name of the repository to be associated with this manifest
+      --sub-path string        the sub path to be set for this manifest
+      --tag string             the tag to be associated with repository in this manifest
+      --target-path string     the target path to be set for this manifest
+      --url string             the repository url to be associated with this manifest
 
diff --git a/cmd/config/testdata/TestConfigSetManifestGoldenOutput/config-cmd-set-manifest-with-help.golden b/cmd/config/testdata/TestConfigSetManifestGoldenOutput/config-cmd-set-manifest-with-help.golden
index 579fc8e7f..e5cdc8d8d 100644
--- a/cmd/config/testdata/TestConfigSetManifestGoldenOutput/config-cmd-set-manifest-with-help.golden
+++ b/cmd/config/testdata/TestConfigSetManifestGoldenOutput/config-cmd-set-manifest-with-help.golden
@@ -29,13 +29,14 @@ airshipctl config set-manifest e2e \
 
 
 Flags:
-      --branch string        the branch to be associated with repository in this manifest
-      --commithash string    the commit hash to be associated with repository in this manifest
-      --force                if set, enable force checkout in repository with this manifest
-  -h, --help                 help for set-manifest
-      --primary              if set, enable this repository as primary repository to be used with this manifest
-      --repo string          the name of the repository to be associated with this manifest
-      --sub-path string      the sub path to be set for this manifest
-      --tag string           the tag to be associated with repository in this manifest
-      --target-path string   the target path for to be set for this manifest
-      --url string           the repository url to be associated with this manifest
+      --branch string          the branch to be associated with repository in this manifest
+      --commithash string      the commit hash to be associated with repository in this manifest
+      --force                  if set, enable force checkout in repository with this manifest
+  -h, --help                   help for set-manifest
+      --metadata-path string   the metadata path to be set for this manifest
+      --primary                if set, enable this repository as primary repository to be used with this manifest
+      --repo string            the name of the repository to be associated with this manifest
+      --sub-path string        the sub path to be set for this manifest
+      --tag string             the tag to be associated with repository in this manifest
+      --target-path string     the target path to be set for this manifest
+      --url string             the repository url to be associated with this manifest
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 475c7728f..d9ef1f101 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -515,6 +515,9 @@ func (c *Config) ModifyManifest(manifest *Manifest, theManifest *ManifestOptions
 	if theManifest.TargetPath != "" {
 		manifest.TargetPath = theManifest.TargetPath
 	}
+	if theManifest.MetadataPath != "" {
+		manifest.MetadataPath = theManifest.MetadataPath
+	}
 	// There is no repository details to be updated
 	if theManifest.RepoName == "" {
 		return nil
diff --git a/pkg/config/options.go b/pkg/config/options.go
index ee1f458cc..ceb294ca0 100644
--- a/pkg/config/options.go
+++ b/pkg/config/options.go
@@ -33,17 +33,18 @@ type ContextOptions struct {
 
 // ManifestOptions holds all configurable options for manifest configuration
 type ManifestOptions struct {
-	Name       string
-	RepoName   string
-	URL        string
-	Branch     string
-	CommitHash string
-	Tag        string
-	RemoteRef  string
-	Force      bool
-	IsPrimary  bool
-	SubPath    string
-	TargetPath string
+	Name         string
+	RepoName     string
+	URL          string
+	Branch       string
+	CommitHash   string
+	Tag          string
+	RemoteRef    string
+	Force        bool
+	IsPrimary    bool
+	SubPath      string
+	TargetPath   string
+	MetadataPath string
 }
 
 // EncryptionConfigOptions holds all configurable options for encryption configuration