Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where unwanted v is prepended to tag name #2915

Merged
merged 4 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/porter/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ func ensureVPrefix(opts *BundleReferenceOptions) error {
ociRef = &ref
}

if strings.HasPrefix(ociRef.Tag(), "v") {
// don't do anything if "v" is already there
if ociRef.Tag() == "" || ociRef.Tag() == "latest" || strings.HasPrefix(ociRef.Tag(), "v") {
// don't do anything if missing tag, if tag is "latest", or if "v" is already there
return nil
}

Expand Down
50 changes: 50 additions & 0 deletions pkg/porter/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,53 @@ func Test_ensureVPrefix_idempotent(t *testing.T) {
})
}
}

// ensure no v is added if specifying :latest tag
func Test_ensureVPrefix_latest(t *testing.T) {
ludfjig marked this conversation as resolved.
Show resolved Hide resolved

latestRef := "example/porter-hello:latest"

t.Run(":latest tag", func(t *testing.T) {
opts := BundleReferenceOptions{
installationOptions: installationOptions{},
BundlePullOptions: BundlePullOptions{
Reference: latestRef,
_ref: nil,
InsecureRegistry: false,
Force: false,
},
bundleRef: nil,
}

err := ensureVPrefix(&opts)
assert.NoError(t, err)

// should be unchanged
assert.Equal(t, latestRef, opts.BundlePullOptions.Reference)
})
}

// ensure no v is added if missing tag
func Test_ensureVPrefix_missing_tag(t *testing.T) {

latestRef := "example/porter-hello"

t.Run(":latest tag", func(t *testing.T) {
opts := BundleReferenceOptions{
installationOptions: installationOptions{},
BundlePullOptions: BundlePullOptions{
Reference: latestRef,
_ref: nil,
InsecureRegistry: false,
Force: false,
},
bundleRef: nil,
}

err := ensureVPrefix(&opts)
assert.NoError(t, err)

// should be unchanged
assert.Equal(t, latestRef, opts.BundlePullOptions.Reference)
})
}
Loading