Skip to content

Commit

Permalink
test: Add test for testing mirror repo with path prefix (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmidyson authored Apr 20, 2023
1 parent d86a719 commit 0736b84
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pkg/credentialprovider/dynamic/dynamic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func Test_dynamicProvider_GetCredentials(t *testing.T) {
}

var tests []test
for _, v := range []string{"v1", "v1beta1", "v1alpha1"} {
for _, v := range []string{"v1", "v1beta1", "v1alpha1", "v1withpath/apath"} {
tests = append(tests, []test{{
name: "mirror only",
name: v + " mirror only",
cfgFile: filepath.Join("testdata", "config-with-mirror-only.yaml"),
img: fmt.Sprintf(dummyImageFmt, v),
want: &credentialproviderv1.CredentialProviderResponse{
Expand All @@ -58,7 +58,7 @@ func Test_dynamicProvider_GetCredentials(t *testing.T) {
},
},
}, {
name: "mirror first",
name: v + " mirror first",
cfgFile: filepath.Join("testdata", "config-with-mirror-first.yaml"),
img: fmt.Sprintf(dummyImageFmt, v),
want: &credentialproviderv1.CredentialProviderResponse{
Expand All @@ -74,7 +74,7 @@ func Test_dynamicProvider_GetCredentials(t *testing.T) {
},
},
}, {
name: "mirror last",
name: v + " mirror last",
cfgFile: filepath.Join("testdata", "config-with-mirror-last.yaml"),
img: fmt.Sprintf(dummyImageFmt, v),
want: &credentialproviderv1.CredentialProviderResponse{
Expand All @@ -90,7 +90,7 @@ func Test_dynamicProvider_GetCredentials(t *testing.T) {
},
},
}, {
name: "mirror and no matching origin",
name: v + " mirror and no matching origin",
cfgFile: filepath.Join("testdata", "config-with-mirror-last.yaml"),
img: "noorigin/image:v1.2.3.4",
want: &credentialproviderv1.CredentialProviderResponse{
Expand All @@ -105,7 +105,7 @@ func Test_dynamicProvider_GetCredentials(t *testing.T) {
},
},
}, {
name: "no mirror",
name: v + " no mirror",
cfgFile: filepath.Join("testdata", "config-no-mirror.yaml"),
img: fmt.Sprintf(dummyImageFmt, v),
want: &credentialproviderv1.CredentialProviderResponse{
Expand Down
4 changes: 4 additions & 0 deletions pkg/credentialprovider/dynamic/testdata/config-no-mirror.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ credentialProviders:
matchImages:
- '*.v1beta1'
apiVersion: credentialprovider.kubelet.k8s.io/v1beta1
- name: staticcredentialprovider-v1-withpath.sh
matchImages:
- '*.v1withpath/apath'
apiVersion: credentialprovider.kubelet.k8s.io/v1
- name: staticcredentialprovider-v1.sh
matchImages:
- '*.v1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ credentialProviders:
matchImages:
- '*.v1'
apiVersion: credentialprovider.kubelet.k8s.io/v1
- name: staticcredentialprovider-v1-withpath.sh
matchImages:
- '*.v1withpath/apath'
apiVersion: credentialprovider.kubelet.k8s.io/v1
- name: staticcredentialprovider-mirror.sh
matchImages:
- someregistry.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ credentialProviders:
matchImages:
- '*.v1'
apiVersion: credentialprovider.kubelet.k8s.io/v1
- name: staticcredentialprovider-v1-withpath.sh
matchImages:
- '*.v1withpath/apath'
apiVersion: credentialprovider.kubelet.k8s.io/v1
- name: staticcredentialprovider-mirror.sh
matchImages:
- someregistry.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ credentialProviders:
matchImages:
- '*.v1'
apiVersion: credentialprovider.kubelet.k8s.io/v1
- name: staticcredentialprovider-v1-withpath.sh
matchImages:
- '*.v1withpath/apath'
apiVersion: credentialprovider.kubelet.k8s.io/v1
- name: staticcredentialprovider-mirror.sh
matchImages:
- someregistry.com
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

# Copyright 2022 D2iQ, Inc. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

echo >&2 "Received Request: "
echo >&2 "$(</dev/stdin)"

echo '{
"kind":"CredentialProviderResponse",
"apiVersion":"credentialprovider.kubelet.k8s.io/v1",
"cacheKeyType":"Image",
"cacheDuration":"5s",
"auth":{
"*.v1withpath/apath": {"username":"v1withpath/apathuser","password":"v1withpath/apathpassword"}
}
}'

0 comments on commit 0736b84

Please sign in to comment.