generated from caicloud/golang-template-project
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to distribution/reference (#224)
Use github.com/docker/distribution/reference for parsing references. Fixes #209 Signed-off-by: Steve Larkin <[email protected]>
- Loading branch information
Showing
2 changed files
with
54 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package oci | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestParseReference(t *testing.T) { | ||
type args struct { | ||
s string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *Reference | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Test single digit tag (from issue #209).", | ||
args: args{s: "foo:1"}, | ||
want: &Reference{Tag: "1", Repo: "foo"}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Test mulitple digit-only tag.", | ||
args: args{s: "registry.example.com/project/repo:1612367"}, | ||
want: &Reference{Tag: "1612367", Repo: "registry.example.com/project/repo"}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ParseReference(tt.args.s) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ParseReference() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ParseReference() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |