mirror of
https://github.com/hauler-dev/hauler.git
synced 2026-02-14 18:09:51 +00:00
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package reference_test
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"hauler.dev/go/hauler/pkg/reference"
|
|
)
|
|
|
|
func TestParse(t *testing.T) {
|
|
type args struct {
|
|
ref string
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "Should add hauler namespace when doesn't exist",
|
|
args: args{
|
|
ref: "myfile",
|
|
},
|
|
want: "hauler/myfile:latest",
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "shouldn't modify namespaced reference",
|
|
args: args{
|
|
ref: "rancher/rancher:latest",
|
|
},
|
|
want: "rancher/rancher:latest",
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "Shouldn't modify canonical reference",
|
|
args: args{
|
|
ref: "index.docker.io/library/registry@sha256:42043edfae481178f07aa077fa872fcc242e276d302f4ac2026d9d2eb65b955f",
|
|
},
|
|
want: "index.docker.io/library/registry@sha256:42043edfae481178f07aa077fa872fcc242e276d302f4ac2026d9d2eb65b955f",
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := reference.Parse(tt.args.ref)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(got.Name(), tt.want) {
|
|
t.Errorf("Parse() got = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|