Skip to content

Commit

Permalink
Default to latest tag (#60)
Browse files Browse the repository at this point in the history
Similar to Tart
  • Loading branch information
fkorotkov authored Nov 13, 2024
1 parent 5a5130e commit c376d63
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 1 addition & 2 deletions internal/name/remotename/remotename.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ func NewFromString(s string) (RemoteName, error) {
return RemoteName{}, fmt.Errorf("%w: remote name cannot have both a tag and a digest",
ErrFailedToParse)
case !isTagged && !isDigested:
return RemoteName{}, fmt.Errorf("%w: remote name should either have a tag or a digest",
ErrFailedToParse)
remoteName.Tag = "latest"
case isTagged:
remoteName.Tag = tagged.Tag()
case isDigested:
Expand Down
11 changes: 8 additions & 3 deletions internal/name/remotename/remotename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ func TestInvalidNoNamespace(t *testing.T) {
require.ErrorIs(t, err, remotename.ErrFailedToParse)
}

func TestInvalidNoTagOrDigest(t *testing.T) {
_, err := remotename.NewFromString("ghcr.io/what/ever")
require.ErrorIs(t, err, remotename.ErrFailedToParse)
func TestDefaultToLatestTag(t *testing.T) {
parsedRemoteName, err := remotename.NewFromString("ghcr.io/what/ever")
require.NoError(t, err)
require.Equal(t, remotename.RemoteName{
Registry: "ghcr.io",
Namespace: "what/ever",
Tag: "latest",
}, parsedRemoteName)
}

func TestInvalidBothTagAndDigest(t *testing.T) {
Expand Down

0 comments on commit c376d63

Please sign in to comment.