Skip to content

Commit

Permalink
getter test
Browse files Browse the repository at this point in the history
  • Loading branch information
rusenask committed Jul 28, 2017
1 parent 855e6ee commit bb9bf97
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions secrets/secrets_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package secrets

import (
"github.com/rusenask/keel/types"
"github.com/rusenask/keel/util/image"

"k8s.io/client-go/pkg/api/v1"

testutil "github.com/rusenask/keel/util/testing"
"testing"
)

var secretDataPayload = `{"https://index.docker.io/v1/":{"username":"user-x","password":"pass-x","email":"[email protected]","auth":"somethinghere"}}`

func TestGetSecret(t *testing.T) {
imgRef, _ := image.Parse("karolisr/webhook-demo:0.0.11")

impl := &testutil.FakeK8sImplementer{
AvailableSecret: &v1.Secret{
Data: map[string][]byte{
dockerConfigJSONKey: []byte(secretDataPayload),
},
Type: v1.SecretTypeDockercfg,
},
}

getter := NewGetter(impl)

trackedImage := &types.TrackedImage{
Image: imgRef,
Namespace: "default",
Secrets: []string{"myregistrysecret"},
}

creds, err := getter.Get(trackedImage)
if err != nil {
t.Errorf("failed to get creds: %s", err)
}

if creds.Username != "user-x" {
t.Errorf("unexpected username: %s", creds.Username)
}

if creds.Password != "pass-x" {
t.Errorf("unexpected pass: %s", creds.Password)
}

}

0 comments on commit bb9bf97

Please sign in to comment.