Repository: getporter/porter
Pull request #1419 (2021-01-14 21:29:17)

fix(*): no really, set reference off of deprecated tag value pls
# What does this change
- Adds fallback for setting reference to the deprecated tag value in commands missed previously

# What issue does it fix
Closes https://github.com/getporter/porter/issues/1418

# Notes for the reviewer

# Checklist
- [x] Unit Tests
- [ ] Documentation
- [ ] Schema (porter.yaml)

If this is your first pull request, please add your name to the bottom of our [Contributors][contributors] list. Thank you for making Porter better! 🙇‍♀️

[contributors]: /CONTRIBUTORS.md


Patch:
diff --git a/pkg/porter/credentials.go b/pkg/porter/credentials.go
index d8916509..3fabf681 100644
--- a/pkg/porter/credentials.go
+++ b/pkg/porter/credentials.go
@@ -70,6 +70,8 @@ type CredentialOptions struct {
 // For example, relative paths are converted to full paths and then checked that
 // they exist and are accessible.
 func (g *CredentialOptions) Validate(args []string, cxt *context.Context) error {
+	g.checkForDeprecatedTagValue()
+
 	err := g.validateCredName(args)
 	if err != nil {
 		return err
diff --git a/pkg/porter/explain.go b/pkg/porter/explain.go
index 087ed8d7..16a861fe 100644
--- a/pkg/porter/explain.go
+++ b/pkg/porter/explain.go
@@ -123,6 +123,8 @@ func (s SortPrintableAction) Swap(i, j int) {
 }
 
 func (o *ExplainOpts) Validate(args []string, cxt *context.Context) error {
+	o.checkForDeprecatedTagValue()
+
 	err := o.validateInstallationName(args)
 	if err != nil {
 		return err
diff --git a/pkg/porter/lifecycle.go b/pkg/porter/lifecycle.go
index 9d04499b..5373d46b 100644
--- a/pkg/porter/lifecycle.go
+++ b/pkg/porter/lifecycle.go
@@ -26,11 +26,7 @@ type BundleActionOptions struct {
 }
 
 func (o *BundleActionOptions) Validate(args []string, porter *Porter) error {
-	// During the deprecation phase of the --tag flag, just assign reference to
-	// the supplied value
-	if o.Tag != "" {
-		o.Reference = o.Tag
-	}
+	o.checkForDeprecatedTagValue()
 
 	if o.Reference != "" {
 		// Ignore anything set based on the bundle directory we are in, go off of the tag
diff --git a/pkg/porter/parameters.go b/pkg/porter/parameters.go
index e4667802..7a25e63f 100644
--- a/pkg/porter/parameters.go
+++ b/pkg/porter/parameters.go
@@ -76,6 +76,8 @@ type ParameterOptions struct {
 // For example, relative paths are converted to full paths and then checked that
 // they exist and are accessible.
 func (g *ParameterOptions) Validate(args []string, cxt *context.Context) error {
+	g.checkForDeprecatedTagValue()
+
 	err := g.validateParamName(args)
 	if err != nil {
 		return err
diff --git a/pkg/porter/pull.go b/pkg/porter/pull.go
index b0d4633c..84c76b8f 100644
--- a/pkg/porter/pull.go
+++ b/pkg/porter/pull.go
@@ -14,6 +14,14 @@ type BundlePullOptions struct {
 	Force            bool
 }
 
+func (b *BundlePullOptions) checkForDeprecatedTagValue() {
+	// During the deprecation phase of the --tag flag, just assign reference to
+	// the supplied value
+	if b.Tag != "" {
+		b.Reference = b.Tag
+	}
+}
+
 func (b BundlePullOptions) validateReference() error {
 	_, err := cnabtooci.ParseOCIReference(b.Reference)
 	if err != nil {


Test patch:
diff --git a/pkg/porter/pull_test.go b/pkg/porter/pull_test.go
index f76ac98e..b2ebe325 100644
--- a/pkg/porter/pull_test.go
+++ b/pkg/porter/pull_test.go
@@ -23,3 +23,25 @@ func TestBundlePullOptions_invalidtag(t *testing.T) {
 	err := opts.validateReference()
 	assert.Error(t, err, "invalid tag should produce an error")
 }
+
+func TestPull_checkForDeprecatedTagValue(t *testing.T) {
+	t.Parallel()
+
+	t.Run("tag not set", func(t *testing.T) {
+		b := BundlePullOptions{}
+
+		b.checkForDeprecatedTagValue()
+		assert.Equal(t, "", b.Tag)
+		assert.Equal(t, "", b.Reference)
+	})
+
+	t.Run("tag set", func(t *testing.T) {
+		b := BundlePullOptions{
+			Tag: "getporter/hello:v0.1.0",
+		}
+
+		b.checkForDeprecatedTagValue()
+		assert.Equal(t, "getporter/hello:v0.1.0", b.Tag)
+		assert.Equal(t, "getporter/hello:v0.1.0", b.Reference)
+	})
+}