cleanup and testing
parent
9862037e11
commit
5ba96cef0a
|
@ -7,7 +7,6 @@ import (
|
|||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/rusenask/keel/provider"
|
||||
"github.com/rusenask/keel/types"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
@ -15,19 +14,6 @@ import (
|
|||
type fakeClient struct {
|
||||
}
|
||||
|
||||
type fakeProvider struct {
|
||||
submitted []types.Event
|
||||
}
|
||||
|
||||
func (p *fakeProvider) Submit(event types.Event) error {
|
||||
p.submitted = append(p.submitted, event)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *fakeProvider) GetName() string {
|
||||
return "fakeProvider"
|
||||
}
|
||||
|
||||
func fakeDoneFunc(id string, done bool) {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -4,12 +4,6 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// "gcr.io/v2-namespace/hello-world:1.1"
|
||||
func extractContainerRegistryURI(imageName string) string {
|
||||
parts := strings.Split(imageName, "/")
|
||||
return parts[0]
|
||||
}
|
||||
|
||||
func containerRegistryURI(projectID, registry string) string {
|
||||
return registry + "%2F" + projectID
|
||||
}
|
||||
|
|
|
@ -2,27 +2,47 @@ package pubsub
|
|||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/rusenask/keel/util/image"
|
||||
)
|
||||
|
||||
func Test_extractContainerRegistryURI(t *testing.T) {
|
||||
func unsafeImageRef(img string) *image.Reference {
|
||||
ref, err := image.Parse(img)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ref
|
||||
}
|
||||
|
||||
func Test_isGoogleContainerRegistry(t *testing.T) {
|
||||
type args struct {
|
||||
imageName string
|
||||
registry string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "gcr.io/v2-namespace/hello-world:1.1",
|
||||
args: args{imageName: "gcr.io/v2-namespace/hello-world:1.1"},
|
||||
want: "gcr.io",
|
||||
name: "gcr",
|
||||
args: args{registry: unsafeImageRef("gcr.io/v2-namespace/hello-world:1.1").Registry()},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "docker registry",
|
||||
args: args{registry: unsafeImageRef("docker.io/v2-namespace/hello-world:1.1").Registry()},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "custom registry",
|
||||
args: args{registry: unsafeImageRef("localhost:4000/v2-namespace/hello-world:1.1").Registry()},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := extractContainerRegistryURI(tt.args.imageName); got != tt.want {
|
||||
t.Errorf("extractContainerRegistryURI() = %v, want %v", got, tt.want)
|
||||
if got := isGoogleContainerRegistry(tt.args.registry); got != tt.want {
|
||||
t.Errorf("isGoogleContainerRegistry() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue