Skip to content

Commit b52870a

Browse files
committed
create binary for conformance tests
Signed-off-by: Tim Ramlot <[email protected]>
1 parent a9c55ba commit b52870a

34 files changed

+702
-551
lines changed

Makefile

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,26 @@ test-e2e-deps: TEST_MODE := E2E
157157
test-e2e-deps: DOCKER_REGISTRY := kind.local
158158
test-e2e-deps: e2e-setup docker-build test-e2e-envs install
159159

160+
$(BINDIR)/conformance.test: | $(NEEDS_GINKGO)
161+
$(GINKGO) build ./conformance/ --trimpath --cover --require-suite
162+
mv ./conformance/conformance.test $@
163+
160164
.PHONY: test
161165
test: test-unit-deps | $(NEEDS_GO) $(NEEDS_GOTESTSUM) ## Run unit tests.
162166
$(GOTESTSUM) ./... -coverprofile cover.out
163167

168+
# $(GOTESTSUM) ./internal/testsetups/simple/e2e/... -coverprofile cover.out -timeout 5m
169+
164170
.PHONY: test-e2e
165-
test-e2e: test-e2e-deps | $(NEEDS_GOTESTSUM) $(NEEDS_GINKGO) ## Run e2e tests. This creates a Kind cluster, installs dependencies, deploys the issuer-lib and runs the E2E tests.
166-
$(GOTESTSUM) ./internal/testsetups/simple/e2e/... -coverprofile cover.out -timeout 5m
171+
test-e2e: test-e2e-deps | $(NEEDS_GOTESTSUM) $(NEEDS_GINKGO) $(BINDIR)/conformance.test ## Run e2e tests. This creates a Kind cluster, installs dependencies, deploys the issuer-lib and runs the E2E tests.
172+
173+
174+
kubectl apply -f internal/testsetups/simple/example/simple-cluster-issuer.yaml
167175

168-
$(GINKGO) ./internal/testsetups/simple/e2e/conformance/...
176+
$(GINKGO) -procs=10 run $(BINDIR)/conformance.test -- \
177+
--cm-issuers=testing.cert-manager.io/SimpleClusterIssuer/simple-cluster-issuer \
178+
--k8s-issuers=simpleclusterissuers.testing.cert-manager.io/simple-cluster-issuer \
179+
--unsupported-features=SaveCAToSecret \
169180

170181
##@ Build
171182

conformance/certificates/suite.go

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
cmmeta "github.com/cert-manager/cert-manager/pkg/apis/meta/v1"
2323
"k8s.io/client-go/rest"
2424

25-
"github.com/cert-manager/issuer-lib/conformance/framework"
26-
"github.com/cert-manager/issuer-lib/conformance/framework/helper/featureset"
25+
"conformance/framework"
26+
"conformance/framework/helper/featureset"
2727

2828
. "github.com/onsi/ginkgo/v2"
2929
)
@@ -39,18 +39,10 @@ type Suite struct {
3939
// This field must be provided.
4040
Name string
4141

42-
// CreateIssuerFunc is a function that provisions a new issuer resource and
43-
// returns an ObjectReference to that Issuer that will be used as the
44-
// IssuerRef on Certificate resources that this suite creates.
45-
// This field must be provided.
46-
CreateIssuerFunc func(*framework.Framework, context.Context) cmmeta.ObjectReference
47-
48-
// DeleteIssuerFunc is a function that is run after the test has completed
49-
// in order to clean up resources created for a test (e.g. the resources
50-
// created in CreateIssuerFunc).
51-
// This function will be run regardless whether the test passes or fails.
52-
// If not specified, this function will be skipped.
53-
DeleteIssuerFunc func(*framework.Framework, context.Context, cmmeta.ObjectReference)
42+
// IssuerRef is reference to the issuer resource that this test suite will
43+
// test against. All Certificate resources created by this suite will be
44+
// created with this issuer reference.
45+
IssuerRef cmmeta.ObjectReference
5446

5547
// DomainSuffix is a suffix used on all domain requests.
5648
// This is useful when the issuer being tested requires special
@@ -76,8 +68,8 @@ func (s *Suite) complete(f *framework.Framework) {
7668
Fail("Name must be set")
7769
}
7870

79-
if s.CreateIssuerFunc == nil {
80-
Fail("CreateIssuerFunc must be set")
71+
if s.IssuerRef != (cmmeta.ObjectReference{}) && s.IssuerRef.Name == "" {
72+
Fail("IssuerRef must be set")
8173
}
8274

8375
if s.DomainSuffix == "" {
@@ -92,20 +84,12 @@ func (s *Suite) complete(f *framework.Framework) {
9284
}
9385

9486
// it is called by the tests to in Define() to setup and run the test
95-
func (s *Suite) it(f *framework.Framework, name string, fn func(cmmeta.ObjectReference), requiredFeatures ...featureset.Feature) {
87+
func (s *Suite) it(f *framework.Framework, name string, fn func(context.Context, cmmeta.ObjectReference), requiredFeatures ...featureset.Feature) {
9688
if !s.checkFeatures(requiredFeatures...) {
9789
return
9890
}
9991
It(name, func(ctx context.Context) {
100-
By("Creating an issuer resource")
101-
issuerRef := s.CreateIssuerFunc(f, ctx)
102-
defer func() {
103-
if s.DeleteIssuerFunc != nil {
104-
By("Cleaning up the issuer resource")
105-
s.DeleteIssuerFunc(f, ctx, issuerRef)
106-
}
107-
}()
108-
fn(issuerRef)
92+
fn(ctx, s.IssuerRef)
10993
})
11094
}
11195

conformance/certificates/tests.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ import (
3434
"k8s.io/apimachinery/pkg/types"
3535
"k8s.io/client-go/util/retry"
3636

37-
"github.com/cert-manager/issuer-lib/conformance/framework"
38-
"github.com/cert-manager/issuer-lib/conformance/framework/helper/featureset"
39-
"github.com/cert-manager/issuer-lib/conformance/framework/helper/validation"
40-
"github.com/cert-manager/issuer-lib/conformance/framework/helper/validation/certificates"
41-
e2eutil "github.com/cert-manager/issuer-lib/conformance/util"
37+
"conformance/framework"
38+
"conformance/framework/helper/featureset"
39+
"conformance/framework/helper/validation"
40+
"conformance/framework/helper/validation/certificates"
41+
e2eutil "conformance/util"
4242

4343
. "github.com/onsi/ginkgo/v2"
4444
. "github.com/onsi/gomega"
@@ -49,7 +49,6 @@ import (
4949
// automatically called.
5050
func (s *Suite) Define() {
5151
Describe("with issuer type "+s.Name, func() {
52-
ctx := context.Background()
5352
f := framework.NewFramework("certificates", s.KubeClientConfig)
5453

5554
sharedIPAddress := "127.0.0.1"
@@ -371,7 +370,7 @@ func (s *Suite) Define() {
371370
}
372371

373372
defineTest := func(test testCase) {
374-
s.it(f, test.name, func(issuerRef cmmeta.ObjectReference) {
373+
s.it(f, test.name, func(ctx context.Context, issuerRef cmmeta.ObjectReference) {
375374
certificate := &cmapi.Certificate{
376375
ObjectMeta: metav1.ObjectMeta{
377376
Name: "testcert",
@@ -393,7 +392,7 @@ func (s *Suite) Define() {
393392
Expect(err).NotTo(HaveOccurred())
394393

395394
By("Waiting for the Certificate to be issued...")
396-
certificate, err = f.Helper().WaitForCertificateReadyAndDoneIssuing(ctx, certificate, time.Minute*8)
395+
certificate, err = f.Helper().WaitForCertificateReadyAndDoneIssuing(ctx, certificate.Name, certificate.Namespace, certificate.Generation, time.Minute*8)
397396
Expect(err).NotTo(HaveOccurred())
398397

399398
By("Validating the issued Certificate...")
@@ -407,7 +406,7 @@ func (s *Suite) Define() {
407406
defineTest(tc)
408407
}
409408

410-
s.it(f, "should issue another certificate with the same private key if the existing certificate and CertificateRequest are deleted", func(issuerRef cmmeta.ObjectReference) {
409+
s.it(f, "should issue another certificate with the same private key if the existing certificate and CertificateRequest are deleted", func(ctx context.Context, issuerRef cmmeta.ObjectReference) {
411410
testCertificate := &cmapi.Certificate{
412411
ObjectMeta: metav1.ObjectMeta{
413412
Name: "testcert",
@@ -424,7 +423,7 @@ func (s *Suite) Define() {
424423
Expect(err).NotTo(HaveOccurred())
425424

426425
By("Waiting for the Certificate to be issued...")
427-
testCertificate, err = f.Helper().WaitForCertificateReadyAndDoneIssuing(ctx, testCertificate, time.Minute*8)
426+
testCertificate, err = f.Helper().WaitForCertificateReadyAndDoneIssuing(ctx, testCertificate.Name, testCertificate.Namespace, testCertificate.Generation, time.Minute*8)
428427
Expect(err).NotTo(HaveOccurred())
429428

430429
By("Validating the issued Certificate...")
@@ -447,7 +446,7 @@ func (s *Suite) Define() {
447446
Expect(err).NotTo(HaveOccurred(), "failed to update secret by deleting the signed certificate data")
448447

449448
By("Waiting for the Certificate to re-issue a certificate")
450-
sec, err = f.Helper().WaitForSecretCertificateData(ctx, f.Namespace.Name, sec.Name, time.Minute*8)
449+
sec, err = f.Helper().WaitForSecretCertificateData(ctx, sec.Name, f.Namespace.Name, time.Minute*8)
451450
Expect(err).NotTo(HaveOccurred(), "failed to wait for secret to have a valid 2nd certificate")
452451

453452
crtPEM2 := sec.Data[corev1.TLSCertKey]
@@ -463,7 +462,7 @@ func (s *Suite) Define() {
463462
}
464463
}, featureset.ReusePrivateKeyFeature, featureset.OnlySAN)
465464

466-
s.it(f, "should allow updating an existing certificate with a new DNS Name", func(issuerRef cmmeta.ObjectReference) {
465+
s.it(f, "should allow updating an existing certificate with a new DNS Name", func(ctx context.Context, issuerRef cmmeta.ObjectReference) {
467466
testCertificate := &cmapi.Certificate{
468467
ObjectMeta: metav1.ObjectMeta{
469468
Name: "testcert",
@@ -482,7 +481,7 @@ func (s *Suite) Define() {
482481
Expect(err).NotTo(HaveOccurred())
483482

484483
By("Waiting for the Certificate to be ready")
485-
testCertificate, err = f.Helper().WaitForCertificateReadyAndDoneIssuing(ctx, testCertificate, time.Minute*8)
484+
testCertificate, err = f.Helper().WaitForCertificateReadyAndDoneIssuing(ctx, testCertificate.Name, testCertificate.Namespace, testCertificate.Generation, time.Minute*8)
486485
Expect(err).NotTo(HaveOccurred())
487486

488487
By("Sanity-check the issued Certificate")
@@ -507,7 +506,7 @@ func (s *Suite) Define() {
507506
Expect(err).NotTo(HaveOccurred())
508507

509508
By("Waiting for the Certificate Ready condition to be updated")
510-
testCertificate, err = f.Helper().WaitForCertificateReadyAndDoneIssuing(ctx, testCertificate, time.Minute*8)
509+
testCertificate, err = f.Helper().WaitForCertificateReadyAndDoneIssuing(ctx, testCertificate.Name, testCertificate.Namespace, testCertificate.Generation, time.Minute*8)
511510
Expect(err).NotTo(HaveOccurred())
512511

513512
By("Sanity-check the issued Certificate")

conformance/certificatesigningrequests/suite.go

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ package certificatesigningrequests
1818

1919
import (
2020
"context"
21-
"crypto"
2221

23-
certificatesv1 "k8s.io/api/certificates/v1"
2422
"k8s.io/client-go/rest"
2523

26-
"github.com/cert-manager/issuer-lib/conformance/framework"
27-
"github.com/cert-manager/issuer-lib/conformance/framework/helper/featureset"
24+
"conformance/framework"
25+
"conformance/framework/helper/featureset"
2826

2927
. "github.com/onsi/ginkgo/v2"
3028
)
@@ -40,32 +38,10 @@ type Suite struct {
4038
// This field must be provided.
4139
Name string
4240

43-
// CreateIssuerFunc is a function that provisions a new issuer resource and
44-
// returns an SignerName to that Issuer that will be used as the SignerName
45-
// on CertificateSigningRequest resources that this suite creates.
46-
// This field must be provided.
47-
CreateIssuerFunc func(*framework.Framework, context.Context) string
48-
49-
// DeleteIssuerFunc is a function that is run after the test has completed
50-
// in order to clean up resources created for a test (e.g. the resources
51-
// created in CreateIssuerFunc).
52-
// This function will be run regardless whether the test passes or fails.
53-
// If not specified, this function will be skipped.
54-
DeleteIssuerFunc func(*framework.Framework, context.Context, string)
55-
56-
// ProvisionFunc is a function that is run every test just before the
57-
// CertificateSigningRequest is created within a test. This is used to
58-
// provision or create any resources that are required by the Issuer to sign
59-
// the CertificateSigningRequest. This could be for example to annotate the
60-
// CertificateSigningRequest, or create a resource like a Secret needed for
61-
// signing.
62-
// If not specified, this function will be skipped.
63-
ProvisionFunc func(*framework.Framework, context.Context, *certificatesv1.CertificateSigningRequest, crypto.Signer)
64-
65-
// DeProvisionFunc is run after every test. This is to be used to remove and
66-
// clean-up any resources which may have been created by ProvisionFunc.
67-
// If not specified, this function will be skipped.
68-
DeProvisionFunc func(*framework.Framework, context.Context, *certificatesv1.CertificateSigningRequest)
41+
// SignerName is the name of the signer that the conformance suite will test
42+
// against. All CertificateSigningRequest resources created by this suite
43+
// will be created with this signer name.
44+
SignerName string
6945

7046
// DomainSuffix is a suffix used on all domain requests.
7147
// This is useful when the issuer being tested requires special
@@ -91,8 +67,8 @@ func (s *Suite) complete(f *framework.Framework) {
9167
Fail("Name must be set")
9268
}
9369

94-
if s.CreateIssuerFunc == nil {
95-
Fail("CreateIssuerFunc must be set")
70+
if s.SignerName == "" {
71+
Fail("SignerName must be set")
9672
}
9773

9874
if s.DomainSuffix == "" {
@@ -112,15 +88,7 @@ func (s *Suite) it(f *framework.Framework, name string, fn func(context.Context,
11288
return
11389
}
11490
It(name, func(ctx context.Context) {
115-
By("Creating an issuer resource")
116-
signerName := s.CreateIssuerFunc(f, ctx)
117-
defer func() {
118-
if s.DeleteIssuerFunc != nil {
119-
By("Cleaning up the issuer resource")
120-
s.DeleteIssuerFunc(f, ctx, signerName)
121-
}
122-
}()
123-
fn(ctx, signerName)
91+
fn(ctx, s.SignerName)
12492
})
12593
}
12694

conformance/certificatesigningrequests/tests.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ import (
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/utils/pointer"
3232

33-
"github.com/cert-manager/issuer-lib/conformance/framework"
34-
"github.com/cert-manager/issuer-lib/conformance/framework/helper/featureset"
35-
"github.com/cert-manager/issuer-lib/conformance/framework/helper/validation"
36-
"github.com/cert-manager/issuer-lib/conformance/framework/helper/validation/certificatesigningrequests"
37-
e2eutil "github.com/cert-manager/issuer-lib/conformance/util"
33+
"conformance/framework"
34+
"conformance/framework/helper/featureset"
35+
"conformance/framework/helper/validation"
36+
"conformance/framework/helper/validation/certificatesigningrequests"
37+
e2eutil "conformance/util"
3838

3939
. "github.com/onsi/ginkgo/v2"
4040
. "github.com/onsi/gomega"
@@ -455,26 +455,12 @@ func (s *Suite) Define() {
455455
},
456456
}
457457

458-
// Provision any resources needed for the request, or modify the
459-
// request based on Issuer requirements
460-
if s.ProvisionFunc != nil {
461-
s.ProvisionFunc(f, ctx, kubeCSR, key)
462-
}
463-
// Ensure related resources are cleaned up at the end of the test
464-
if s.DeProvisionFunc != nil {
465-
defer s.DeProvisionFunc(f, ctx, kubeCSR)
466-
}
467-
468458
// Create the request, and delete at the end of the test
469459
By("Creating a CertificateSigningRequest")
470460
Expect(f.CRClient.Create(ctx, kubeCSR)).NotTo(HaveOccurred())
471-
defer func() {
472-
// Create a new context with a timeout to prevent the deletion of the
473-
// CertificateSigningRequest from blocking test completion.
474-
deleteCtx, cancel := context.WithTimeout(context.Background(), time.Second*30)
475-
defer cancel()
476-
Expect(f.CRClient.Delete(deleteCtx, kubeCSR)).NotTo(HaveOccurred())
477-
}()
461+
DeferCleanup(func(ctx context.Context) {
462+
Expect(f.CRClient.Delete(ctx, kubeCSR)).NotTo(HaveOccurred())
463+
})
478464

479465
// Approve the request for testing, so that cert-manager may sign the
480466
// request.

0 commit comments

Comments
 (0)