Skip to content

Commit 2994c60

Browse files
author
Mengqi Yu
committed
add some tests
1 parent 4e583ee commit 2994c60

File tree

5 files changed

+624
-4
lines changed

5 files changed

+624
-4
lines changed

pkg/admission/certprovisioner/certprovisioner_test.go renamed to pkg/admission/certgenerator/certgenerator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package certprovisioner
17+
package certgenerator
1818

1919
import "fmt"
2020

pkg/admission/certprovisioner/selfsignedcertprovisioner_test.go renamed to pkg/admission/certgenerator/selfsigned_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package certprovisioner
17+
package certgenerator
1818

1919
import (
2020
"crypto/x509"
@@ -24,8 +24,8 @@ import (
2424

2525
func TestProvisionServingCert(t *testing.T) {
2626
cn := "mysvc.myns.svc"
27-
cp := SelfSignedCertProvisioner{CommonName: cn}
28-
certs, _ := cp.ProvisionServingCert()
27+
cp := SelfSignedCertGenerator{}
28+
certs, _ := cp.Generate(cn)
2929

3030
// First, create the set of root certificates. For this example we only
3131
// have one. It's also possible to omit this in order to use the
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package certwriter
18+
19+
import (
20+
//. "github.com/onsi/ginkgo"
21+
//. "github.com/onsi/gomega"
22+
23+
. "github.com/onsi/ginkgo"
24+
. "github.com/onsi/gomega"
25+
26+
"sigs.k8s.io/controller-runtime/pkg/admission/certgenerator"
27+
"sigs.k8s.io/controller-runtime/pkg/client"
28+
"sigs.k8s.io/controller-runtime/pkg/client/fake"
29+
)
30+
31+
var _ = Describe("NewProvider", func() {
32+
var cl client.Client
33+
var ops Options
34+
var expectedProvider CertWriterProvider
35+
BeforeEach(func() {
36+
ops = Options{}
37+
})
38+
39+
Describe("required client is missing", func() {
40+
It("should return an error", func() {
41+
_, err := NewProvider(ops)
42+
Expect(err).To(MatchError("Options.Client is required"))
43+
})
44+
})
45+
46+
Describe("succeed", func() {
47+
BeforeEach(func() {
48+
cl = fake.NewFakeClient()
49+
ops.Client = cl
50+
expectedProvider = &MultiCertWriterProvider{
51+
CertWriterProviders: []CertWriterProvider{
52+
&SecretCertWriterProvider{
53+
Client: cl,
54+
CertGenerator: &certgenerator.SelfSignedCertGenerator{},
55+
},
56+
&FSCertWriterProvider{
57+
CertGenerator: &certgenerator.SelfSignedCertGenerator{},
58+
},
59+
},
60+
}
61+
})
62+
It("should successfully return a Provider", func() {
63+
provider, err := NewProvider(ops)
64+
Expect(err).NotTo(HaveOccurred())
65+
Expect(provider).To(Equal(expectedProvider))
66+
})
67+
})
68+
69+
})

0 commit comments

Comments
 (0)