Skip to content

Commit

Permalink
Merge pull request #272 from vmware-tanzu/fix-ggcr-tests
Browse files Browse the repository at this point in the history
Fix tests for ggcr bump
  • Loading branch information
Tyler Phelan authored Nov 17, 2022
2 parents c29ecdb + 28bd24c commit 6322530
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions pkg/commands/secret/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
registryUser = "my-registry-user"
registryPassword = "dummy-password"
secretName = "my-registry-cred"
expectedRegistryConfig = fmt.Sprintf("{\"auths\":{\"%s\":{\"username\":\"%s\",\"password\":\"%s\"}}}", registry, registryUser, registryPassword)
expectedRegistryConfig = fmt.Sprintf("{\"auths\":{\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"auth\":\"bXktcmVnaXN0cnktdXNlcjpkdW1teS1wYXNzd29yZA==\"}}}", registry, registryUser, registryPassword)
)

fetcher.passwords["REGISTRY_PASSWORD"] = registryPassword
Expand Down Expand Up @@ -114,7 +114,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
dockerhubId = "my-dockerhub-id"
dockerPassword = "dummy-password"
secretName = "my-docker-cred"
expectedDockerConfig = fmt.Sprintf("{\"auths\":{\"https://index.docker.io/v1/\":{\"username\":\"%s\",\"password\":\"%s\"}}}", dockerhubId, dockerPassword)
expectedDockerConfig = fmt.Sprintf(`{"auths":{"https://index.docker.io/v1/":{"username":"%s","password":"%s","auth":"bXktZG9ja2VyaHViLWlkOmR1bW15LXBhc3N3b3Jk"}}}`, dockerhubId, dockerPassword)
)

fetcher.passwords["DOCKER_PASSWORD"] = dockerPassword
Expand Down Expand Up @@ -154,7 +154,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
registryUser = "my-registry-user"
registryPassword = "dummy-password"
secretName = "my-registry-cred"
expectedRegistryConfig = fmt.Sprintf("{\"auths\":{\"%s\":{\"username\":\"%s\",\"password\":\"%s\"}}}", registry, registryUser, registryPassword)
expectedRegistryConfig = fmt.Sprintf(`{"auths":{"%s":{"username":"%s","password":"%s","auth":"bXktcmVnaXN0cnktdXNlcjpkdW1teS1wYXNzd29yZA=="}}}`, registry, registryUser, registryPassword)
)

fetcher.passwords["REGISTRY_PASSWORD"] = registryPassword
Expand Down Expand Up @@ -192,7 +192,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
var (
gcrServiceAccountFile = "./testdata/gcr-service-account.json"
secretName = "my-gcr-cred"
expectedRegistryConfig = fmt.Sprintf(`{"auths":{"%s":{"username":"%s","password":"{\"some-key\":\"some-value\"}"}}}`, secret.GcrUrl, secret.GcrUser)
expectedRegistryConfig = fmt.Sprintf(`{"auths":{"%s":{"username":"%s","password":"{\"some-key\":\"some-value\"}","auth":"X2pzb25fa2V5Onsic29tZS1rZXkiOiJzb21lLXZhbHVlIn0="}}}`, secret.GcrUrl, secret.GcrUser)
)

fetcher.passwords[gcrServiceAccountFile] = `{"some-key":"some-value"}`
Expand Down Expand Up @@ -317,7 +317,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
dockerhubId = "my-dockerhub-id"
dockerPassword = "dummy-password"
secretName = "my-docker-cred"
expectedDockerConfig = fmt.Sprintf("{\"auths\":{\"https://index.docker.io/v1/\":{\"username\":\"%s\",\"password\":\"%s\"}}}", dockerhubId, dockerPassword)
expectedDockerConfig = fmt.Sprintf(`{"auths":{"https://index.docker.io/v1/":{"username":"%s","password":"%s","auth":"bXktZG9ja2VyaHViLWlkOmR1bW15LXBhc3N3b3Jk"}}}`, dockerhubId, dockerPassword)
)

fetcher.passwords["DOCKER_PASSWORD"] = dockerPassword
Expand Down Expand Up @@ -357,7 +357,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
registryUser = "my-registry-user"
registryPassword = "dummy-password"
secretName = "my-registry-cred"
expectedRegistryConfig = fmt.Sprintf("{\"auths\":{\"%s\":{\"username\":\"%s\",\"password\":\"%s\"}}}", registry, registryUser, registryPassword)
expectedRegistryConfig = fmt.Sprintf(`{"auths":{"%s":{"username":"%s","password":"%s","auth":"bXktcmVnaXN0cnktdXNlcjpkdW1teS1wYXNzd29yZA=="}}}`, registry, registryUser, registryPassword)
)

fetcher.passwords["REGISTRY_PASSWORD"] = registryPassword
Expand Down Expand Up @@ -395,7 +395,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
var (
gcrServiceAccountFile = "./testdata/gcr-service-account.json"
secretName = "my-gcr-cred"
expectedRegistryConfig = fmt.Sprintf(`{"auths":{"%s":{"username":"%s","password":"{\"some-key\":\"some-value\"}"}}}`, secret.GcrUrl, secret.GcrUser)
expectedRegistryConfig = fmt.Sprintf(`{"auths":{"%s":{"username":"%s","password":"{\"some-key\":\"some-value\"}","auth":"X2pzb25fa2V5Onsic29tZS1rZXkiOiJzb21lLXZhbHVlIn0="}}}`, secret.GcrUrl, secret.GcrUser)
)

fetcher.passwords[gcrServiceAccountFile] = `{"some-key":"some-value"}`
Expand Down Expand Up @@ -519,7 +519,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
dockerhubId = "my-dockerhub-id"
dockerPassword = "dummy-password"
secretName = "my-docker-cred"
expectedDockerConfig = fmt.Sprintf("{\"auths\":{\"https://index.docker.io/v1/\":{\"username\":\"%s\",\"password\":\"%s\"}}}", dockerhubId, dockerPassword)
expectedDockerConfig = fmt.Sprintf(`{"auths":{"https://index.docker.io/v1/":{"username":"%s","password":"%s","auth":"bXktZG9ja2VyaHViLWlkOmR1bW15LXBhc3N3b3Jk"}}}`, dockerhubId, dockerPassword)
)

expectedDockerSecret := &corev1.Secret{
Expand All @@ -538,7 +538,7 @@ func testSecretCreateCommand(t *testing.T, when spec.G, it spec.S) {
it("can output in yaml format", func() {
const resourceYAML = `apiVersion: v1
data:
.dockerconfigjson: eyJhdXRocyI6eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsidXNlcm5hbWUiOiJteS1kb2NrZXJodWItaWQiLCJwYXNzd29yZCI6ImR1bW15LXBhc3N3b3JkIn19fQ==
.dockerconfigjson: eyJhdXRocyI6eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsidXNlcm5hbWUiOiJteS1kb2NrZXJodWItaWQiLCJwYXNzd29yZCI6ImR1bW15LXBhc3N3b3JkIiwiYXV0aCI6ImJYa3RaRzlqYTJWeWFIVmlMV2xrT21SMWJXMTVMWEJoYzNOM2IzSmsifX19
kind: Secret
metadata:
creationTimestamp: null
Expand Down Expand Up @@ -589,7 +589,7 @@ secrets:
"creationTimestamp": null
},
"data": {
".dockerconfigjson": "eyJhdXRocyI6eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsidXNlcm5hbWUiOiJteS1kb2NrZXJodWItaWQiLCJwYXNzd29yZCI6ImR1bW15LXBhc3N3b3JkIn19fQ=="
".dockerconfigjson": "eyJhdXRocyI6eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsidXNlcm5hbWUiOiJteS1kb2NrZXJodWItaWQiLCJwYXNzd29yZCI6ImR1bW15LXBhc3N3b3JkIiwiYXV0aCI6ImJYa3RaRzlqYTJWeWFIVmlMV2xrT21SMWJXMTVMWEJoYzNOM2IzSmsifX19"
},
"type": "kubernetes.io/dockerconfigjson"
}
Expand Down Expand Up @@ -659,7 +659,7 @@ secrets:
it("does not create the secret and prints resource output", func() {
const resourceYAML = `apiVersion: v1
data:
.dockerconfigjson: eyJhdXRocyI6eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsidXNlcm5hbWUiOiJteS1kb2NrZXJodWItaWQiLCJwYXNzd29yZCI6ImR1bW15LXBhc3N3b3JkIn19fQ==
.dockerconfigjson: eyJhdXRocyI6eyJodHRwczovL2luZGV4LmRvY2tlci5pby92MS8iOnsidXNlcm5hbWUiOiJteS1kb2NrZXJodWItaWQiLCJwYXNzd29yZCI6ImR1bW15LXBhc3N3b3JkIiwiYXV0aCI6ImJYa3RaRzlqYTJWeWFIVmlMV2xrT21SMWJXMTVMWEJoYzNOM2IzSmsifX19
kind: Secret
metadata:
creationTimestamp: null
Expand Down
4 changes: 2 additions & 2 deletions pkg/secret/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func testSecretFactory(t *testing.T, when spec.G, it spec.S) {
require.NoError(t, err)
require.Equal(t, "test-name", s.Name)
require.Equal(t, "test-namespace", s.Namespace)
require.Equal(t, `{"auths":{"registry.io":{"username":"some-reg-user","password":"foo"}}}`, string(s.Data[".dockerconfigjson"]))
require.Equal(t, `{"auths":{"registry.io":{"username":"some-reg-user","password":"foo","auth":"c29tZS1yZWctdXNlcjpmb28="}}}`, string(s.Data[".dockerconfigjson"]))
})

when("no params are set", func() {
Expand Down Expand Up @@ -83,7 +83,7 @@ func testSecretFactory(t *testing.T, when spec.G, it spec.S) {
factory.RegistryUser = "some-reg-user"
s, _, err := factory.MakeSecret("test-name", "test-namespace")
require.NoError(t, err)
require.Equal(t, `{"auths":{"registry.io":{"username":"some-reg-user","password":"foo"}}}`, string(s.Data[".dockerconfigjson"]))
require.Equal(t, `{"auths":{"registry.io":{"username":"some-reg-user","password":"foo","auth":"c29tZS1yZWctdXNlcjpmb28="}}}`, string(s.Data[".dockerconfigjson"]))
})
})

Expand Down

0 comments on commit 6322530

Please sign in to comment.