Adds a test for copying the annotations from Certificate
Signed-off-by: irbekrm <irbekrm@gmail.com>
This commit is contained in:
parent
ddf7e130b7
commit
143c5ce38d
@ -60,6 +60,7 @@ go_test(
|
||||
deps = [
|
||||
"//pkg/apis/certmanager/v1:go_default_library",
|
||||
"//pkg/util/pki:go_default_library",
|
||||
"//test/unit/gen:go_default_library",
|
||||
"@com_github_stretchr_testify//assert:go_default_library",
|
||||
"@io_k8s_api//core/v1:go_default_library",
|
||||
"@io_k8s_apimachinery//pkg/apis/meta/v1:go_default_library",
|
||||
|
||||
@ -29,6 +29,7 @@ import (
|
||||
|
||||
cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
|
||||
"github.com/jetstack/cert-manager/pkg/util/pki"
|
||||
"github.com/jetstack/cert-manager/test/unit/gen"
|
||||
)
|
||||
|
||||
func mustGenerateRSA(t *testing.T, keySize int) crypto.PrivateKey {
|
||||
@ -352,3 +353,50 @@ func TestRenewalTime(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
func TestBuildAnnotationsToCopy(t *testing.T) {
|
||||
testCert := gen.Certificate("test")
|
||||
tests := map[string]struct {
|
||||
cert *cmapi.Certificate
|
||||
copiedAnnotations []string
|
||||
want map[string]string
|
||||
}{
|
||||
"no annotations should be copied": {
|
||||
cert: gen.CertificateFrom(testCert,
|
||||
gen.AddCertificateAnnotations(map[string]string{"foo": "bar", "bar": "bat"})),
|
||||
copiedAnnotations: []string{},
|
||||
want: make(map[string]string),
|
||||
},
|
||||
"all annotations should be copied": {
|
||||
cert: gen.CertificateFrom(testCert,
|
||||
gen.AddCertificateAnnotations(map[string]string{"foo": "bar", "bar": "bat"})),
|
||||
copiedAnnotations: []string{"*"},
|
||||
want: map[string]string{"foo": "bar", "bar": "bat"},
|
||||
},
|
||||
"all except some should be copied": {
|
||||
cert: gen.CertificateFrom(testCert,
|
||||
gen.AddCertificateAnnotations(map[string]string{"foo": "bar", "foo.io/thing": "bar", "foo.io/anotherthing": "bat", "bar": "bat"})),
|
||||
copiedAnnotations: []string{"*", "-foo.io/"},
|
||||
want: map[string]string{"foo": "bar", "bar": "bat"},
|
||||
},
|
||||
"only some should be copied": {
|
||||
cert: gen.CertificateFrom(testCert,
|
||||
gen.AddCertificateAnnotations(map[string]string{
|
||||
"foo": "bar", "foo.io/thing": "bar", "foo.io/anotherthing": "bat", "bar": "bat",
|
||||
})),
|
||||
copiedAnnotations: []string{"foo.io/"},
|
||||
want: map[string]string{"foo.io/thing": "bar", "foo.io/anotherthing": "bat"},
|
||||
},
|
||||
"some annotations have been specified, but none found on the cert": {
|
||||
cert: gen.CertificateFrom(testCert),
|
||||
copiedAnnotations: []string{"*", "-foo.io/"},
|
||||
want: map[string]string{},
|
||||
},
|
||||
}
|
||||
for name, test := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
if got := BuildAnnotationsToCopy(test.cert, test.copiedAnnotations); !reflect.DeepEqual(got, test.want) {
|
||||
t.Errorf("BuildAnnotationsToCopy() = %+#v, want %+#v", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user