cleanup and testing

pull/39/head
Karolis Rusenas 2017-07-20 20:39:19 +01:00
parent 9862037e11
commit 5ba96cef0a
3 changed files with 28 additions and 28 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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)
}
})
}