From 5ba96cef0a5231d521d5e6773b0be1d5891955ae Mon Sep 17 00:00:00 2001 From: Karolis Rusenas Date: Thu, 20 Jul 2017 20:39:19 +0100 Subject: [PATCH] cleanup and testing --- trigger/pubsub/pubsub_test.go | 14 -------------- trigger/pubsub/util.go | 6 ------ trigger/pubsub/util_test.go | 36 +++++++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/trigger/pubsub/pubsub_test.go b/trigger/pubsub/pubsub_test.go index 572e1be7..7394d656 100644 --- a/trigger/pubsub/pubsub_test.go +++ b/trigger/pubsub/pubsub_test.go @@ -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 } diff --git a/trigger/pubsub/util.go b/trigger/pubsub/util.go index 80742f28..15cd1698 100644 --- a/trigger/pubsub/util.go +++ b/trigger/pubsub/util.go @@ -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 } diff --git a/trigger/pubsub/util_test.go b/trigger/pubsub/util_test.go index 336912ab..88eb27ae 100644 --- a/trigger/pubsub/util_test.go +++ b/trigger/pubsub/util_test.go @@ -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) } }) }