Fix integration tests

Signed-off-by: irbekrm <irbekrm@gmail.com>
This commit is contained in:
irbekrm 2023-01-05 12:07:25 +00:00
parent 036b013942
commit 8ed0faf228
4 changed files with 33 additions and 10 deletions

View File

@ -33,6 +33,8 @@ import (
logf "github.com/cert-manager/cert-manager/pkg/logs"
)
const SolverName = "rfc2136"
type Solver struct {
secretLister corelisters.SecretLister
@ -65,7 +67,7 @@ func New(opts ...Option) *Solver {
}
func (s *Solver) Name() string {
return "rfc2136"
return SolverName
}
func (s *Solver) Present(ch *whapi.ChallengeRequest) error {
@ -112,7 +114,6 @@ func (s *Solver) Initialize(kubeClientConfig *restclient.Config, stopCh <-chan s
factory.Start(stopCh)
factory.WaitForCacheSync(stopCh)
}
return nil
}

View File

@ -24,10 +24,12 @@ import (
"time"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"github.com/cert-manager/cert-manager/pkg/acme/webhook"
"github.com/cert-manager/cert-manager/pkg/issuer/acme/dns/rfc2136"
"github.com/cert-manager/cert-manager/test/internal/apiserver"
)
@ -42,7 +44,8 @@ func init() {
type fixture struct {
// testSolver is the actual DNS solver that is under test.
// It is set when calling the NewFixture function.
testSolver webhook.Solver
testSolver webhook.Solver
testSolverType string
resolvedFQDN string
resolvedZone string
@ -96,7 +99,28 @@ func (f *fixture) setup(t *testing.T) func() {
f.clientset = cl
stopCh := make(chan struct{})
f.testSolver.Initialize(env.Config, stopCh)
var testSolver webhook.Solver
switch f.testSolverType {
case rfc2136.SolverName:
cl, err := kubernetes.NewForConfig(env.Config)
if err != nil {
t.Errorf("error initializing solver: %#+v", err)
}
// obtain a secret lister and start the informer factory to populate the
// secret cache
factory := informers.NewSharedInformerFactoryWithOptions(cl, time.Minute*5)
secretLister := factory.Core().V1().Secrets().Lister()
factory.Start(stopCh)
factory.WaitForCacheSync(stopCh)
testSolver = rfc2136.New(rfc2136.WithSecretsLister(secretLister))
f.testSolver = testSolver
default:
t.Errorf("unknown solver type: %s", f.testSolverType)
}
testSolver.Initialize(env.Config, stopCh)
return func() {
close(stopCh)

View File

@ -24,8 +24,6 @@ import (
"time"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"github.com/cert-manager/cert-manager/pkg/acme/webhook"
)
// Option applies a configuration option to the test fixture being built
@ -33,9 +31,9 @@ type Option func(*fixture)
// NewFixture constructs a new *fixture, applying the given Options before
// returning.
func NewFixture(solver webhook.Solver, opts ...Option) *fixture {
func NewFixture(solverType string, opts ...Option) *fixture {
f := &fixture{
testSolver: solver,
testSolverType: solverType,
}
for _, o := range opts {
o(f)

View File

@ -59,7 +59,7 @@ func TestRunSuiteWithTSIG(t *testing.T) {
TSIGKeyName: rfc2136TestTsigKeyName,
}
fixture := dns.NewFixture(&rfc2136.Solver{},
fixture := dns.NewFixture(rfc2136.SolverName,
dns.SetResolvedZone(rfc2136TestZone),
dns.SetResolvedFQDN(rfc2136TestFqdn),
dns.SetAllowAmbientCredentials(false),
@ -91,7 +91,7 @@ func TestRunSuiteNoTSIG(t *testing.T) {
Nameserver: server.ListenAddr(),
}
fixture := dns.NewFixture(&rfc2136.Solver{},
fixture := dns.NewFixture(rfc2136.SolverName,
dns.SetResolvedZone(rfc2136TestZone),
dns.SetResolvedFQDN(rfc2136TestFqdn),
dns.SetAllowAmbientCredentials(false),