Skip to content

Commit

Permalink
Merge pull request #1419 from vdice/fix/tag-for-reference
Browse files Browse the repository at this point in the history
fix(*): no really, set reference off of deprecated tag value pls
  • Loading branch information
carolynvs authored Jan 14, 2021
2 parents 00fa5f2 + ab21a2f commit 537c1b2
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
2 changes: 2 additions & 0 deletions pkg/porter/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/porter/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions pkg/porter/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/porter/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions pkg/porter/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions pkg/porter/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

0 comments on commit 537c1b2

Please sign in to comment.