Fix tests for conditions. Add test for failed registration.
This commit is contained in:
parent
a958f4462d
commit
6d302c57e3
@ -48,12 +48,32 @@ var _ = framework.CertManagerDescribe("Issuer", func() {
|
||||
_, err := f.CertManagerClientSet.CertmanagerV1alpha1().Issuers(f.Namespace.Name).Create(newCertManagerACMEIssuer(issuerName, testingACMEURL, testingACMEEmail, testingACMEPrivateKey))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
By("Waiting for Issuer to become Ready")
|
||||
err = util.WaitForIssuerReady(f.CertManagerClientSet.CertmanagerV1alpha1().Issuers(f.Namespace.Name), issuerName)
|
||||
err = util.WaitForIssuerCondition(f.CertManagerClientSet.CertmanagerV1alpha1().Issuers(f.Namespace.Name),
|
||||
issuerName,
|
||||
v1alpha1.IssuerCondition{
|
||||
Type: v1alpha1.IssuerConditionReady,
|
||||
Status: v1alpha1.ConditionTrue,
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
It("should fail to register an ACME account", func() {
|
||||
By("Creating an Issuer with an invalid server")
|
||||
_, err := f.CertManagerClientSet.CertmanagerV1alpha1().Issuers(f.Namespace.Name).Create(newCertManagerACMEIssuer(issuerName, invalidACMEURL, testingACMEEmail, testingACMEPrivateKey))
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
By("Waiting for Issuer to become non-Ready")
|
||||
err = util.WaitForIssuerCondition(f.CertManagerClientSet.CertmanagerV1alpha1().Issuers(f.Namespace.Name),
|
||||
issuerName,
|
||||
v1alpha1.IssuerCondition{
|
||||
Type: v1alpha1.IssuerConditionReady,
|
||||
Status: v1alpha1.ConditionFalse,
|
||||
})
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
const testingACMEURL = "https://acme-staging.api.letsencrypt.org/directory"
|
||||
const invalidACMEURL = "http://not-a-real-acme-url.com"
|
||||
const testingACMEEmail = "test@example.com"
|
||||
const testingACMEPrivateKey = "test-acme-private-key"
|
||||
|
||||
|
||||
@ -7,19 +7,30 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"github.com/jetstack-experimental/cert-manager/pkg/apis/certmanager/v1alpha1"
|
||||
clientset "github.com/jetstack-experimental/cert-manager/pkg/client/typed/certmanager/v1alpha1"
|
||||
)
|
||||
|
||||
func WaitForIssuerReady(cl clientset.IssuerInterface, name string) error {
|
||||
// WaitForIssuerCondition waits for the status of the named issuer to contain
|
||||
// a condition whose type and status matches the supplied one.
|
||||
func WaitForIssuerCondition(client clientset.IssuerInterface, name string, condition v1alpha1.IssuerCondition) error {
|
||||
return wait.PollImmediate(500*time.Millisecond, wait.ForeverTestTimeout,
|
||||
func() (bool, error) {
|
||||
issuer, err := cl.Get(name, metav1.GetOptions{})
|
||||
glog.V(5).Infof("Waiting for issuer %v condition %#v", name, condition)
|
||||
issuer, err := client.Get(name, metav1.GetOptions{})
|
||||
if nil != err {
|
||||
return false, fmt.Errorf("error getting Broker %v: %v", name, err)
|
||||
return false, fmt.Errorf("error getting Issuer %v: %v", name, err)
|
||||
}
|
||||
|
||||
if issuer.Status.Ready {
|
||||
return true, nil
|
||||
if len(issuer.Status.Conditions) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
for _, cond := range issuer.Status.Conditions {
|
||||
if condition.Type == cond.Type && condition.Status == cond.Status {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
return false, nil
|
||||
|
||||
Loading…
Reference in New Issue
Block a user