Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit test build issues #210

Merged
merged 1 commit into from Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 23 additions & 23 deletions pkg/certificates/controller.go
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/appscode/errors"
"github.com/appscode/go/strings"
"github.com/appscode/log"
aci "github.com/appscode/voyager/api"
"github.com/appscode/voyager/api"
acs "github.com/appscode/voyager/client/clientset"
"github.com/appscode/voyager/pkg/certificates/providers"
"github.com/appscode/voyager/pkg/events"
Expand Down Expand Up @@ -43,7 +43,7 @@ type CertificateController struct {
KubeClient clientset.Interface
ExtClient acs.ExtensionInterface

certificate *aci.Certificate
certificate *api.Certificate
acmeCert ACMECertData
parsedCertificate *x509.Certificate
sync.Mutex
Expand All @@ -70,16 +70,16 @@ func (c *CertificateController) Handle(e *events.Event) error {

func (c *CertificateController) handleCertificateEvent(e *events.Event) error {
if e.EventType == events.Added || e.EventType == events.Updated {
var cert *aci.Certificate
var cert *api.Certificate

// Indicates event contains an certificate to operate with
ok := false
switch e.EventType {
case events.Added:
cert, ok = e.RuntimeObj[0].(*aci.Certificate)
cert, ok = e.RuntimeObj[0].(*api.Certificate)
case events.Updated:
if len(e.RuntimeObj) > 1 {
cert, ok = e.RuntimeObj[1].(*aci.Certificate)
cert, ok = e.RuntimeObj[1].(*api.Certificate)
}
}
if ok {
Expand All @@ -90,7 +90,7 @@ func (c *CertificateController) handleCertificateEvent(e *events.Event) error {
return nil
}

func (c *CertificateController) process(cert *aci.Certificate) error {
func (c *CertificateController) process(cert *api.Certificate) error {
c.acmeClientConfig = &ACMEConfig{
Provider: cert.Spec.Provider,
ACMEServerUrl: cert.Spec.ACMEServerURL,
Expand Down Expand Up @@ -129,14 +129,14 @@ func (c *CertificateController) process(cert *aci.Certificate) error {
}

func (c *CertificateController) handleIngressEvent(e *events.Event) error {
var ingress *aci.Ingress
var ingress *api.Ingress
ok := false
switch e.EventType {
case events.Added:
ingress, ok = e.RuntimeObj[0].(*aci.Ingress)
ingress, ok = e.RuntimeObj[0].(*api.Ingress)
case events.Updated:
if len(e.RuntimeObj) > 1 {
ingress, ok = e.RuntimeObj[1].(*aci.Ingress)
ingress, ok = e.RuntimeObj[1].(*api.Ingress)
}
}

Expand All @@ -150,12 +150,12 @@ func (c *CertificateController) handleIngressEvent(e *events.Event) error {
return nil
}
if kerr.IsNotFound(err) || !certificate.Status.CertificateObtained {
newCertificate := &aci.Certificate{
newCertificate := &api.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: certificateName,
Namespace: ingress.Namespace,
},
Spec: aci.CertificateSpec{
Spec: api.CertificateSpec{
Provider: ingress.Annotations[certificateAnnotationKeyProvider],
Email: ingress.Annotations[certificateAnnotationKeyEmail],
ProviderCredentialSecretName: ingress.Annotations[certificateAnnotationKeyProviderCredentialSecretName],
Expand All @@ -170,11 +170,11 @@ func (c *CertificateController) handleIngressEvent(e *events.Event) error {
ACMEServerURL: ingress.Annotations[certificateAnnotationKeyACMEServerURL],
},
}
if v, ok := ingress.Annotations[aci.APISchema]; ok {
if v == aci.APISchemaIngress {
newCertificate.Spec.HTTPProviderIngressReference.APIVersion = aci.APISchemaIngress
if v, ok := ingress.Annotations[api.APISchema]; ok {
if v == api.APISchemaIngress {
newCertificate.Spec.HTTPProviderIngressReference.APIVersion = api.APISchemaIngress
} else {
newCertificate.Spec.HTTPProviderIngressReference.APIVersion = aci.APISchemaEngress
newCertificate.Spec.HTTPProviderIngressReference.APIVersion = api.APISchemaEngress
}
}
for _, rule := range ingress.Spec.Rules {
Expand Down Expand Up @@ -395,11 +395,11 @@ func (c *CertificateController) save(cert acme.CertificateResource) error {

// Update certificate data to add Details Information
t := metav1.Now()
k8sCert.Status = aci.CertificateStatus{
k8sCert.Status = api.CertificateStatus{
CertificateObtained: true,
CreationTime: &t,
ACMEUserSecretName: c.userSecretName,
Details: aci.ACMECertificateDetails{
Details: api.ACMECertificateDetails{
Domain: cert.Domain,
CertURL: cert.CertURL,
CertStableURL: cert.CertStableURL,
Expand Down Expand Up @@ -445,14 +445,14 @@ func (c *CertificateController) processHTTPCertificate(revert chan struct{}) err
// make a copy of previous spec.
prevSpecs := i.Spec
for _, host := range c.certificate.Spec.Domains {
rule := aci.ExtendedIngressRule{
rule := api.ExtendedIngressRule{
Host: host,
ExtendedIngressRuleValue: aci.ExtendedIngressRuleValue{
HTTP: &aci.HTTPExtendedIngressRuleValue{
Paths: []aci.HTTPExtendedIngressPath{
ExtendedIngressRuleValue: api.ExtendedIngressRuleValue{
HTTP: &api.HTTPExtendedIngressRuleValue{
Paths: []api.HTTPExtendedIngressPath{
{
Path: providers.URLPrefix,
Backend: aci.ExtendedIngressBackend{
Backend: api.ExtendedIngressBackend{
ServiceName: "kubed.kube-system",
ServicePort: intstr.FromInt(8765),
},
Expand All @@ -478,7 +478,7 @@ func (c *CertificateController) processHTTPCertificate(revert chan struct{}) err
Get(c.certificate.Spec.HTTPProviderIngressReference.Name)
if err == nil {
i.Spec = prevSpecs
i.Spec.TLS = append(i.Spec.TLS, aci.ExtendedIngressTLS{
i.Spec.TLS = append(i.Spec.TLS, api.ExtendedIngressTLS{
Hosts: c.certificate.Spec.Domains,
SecretName: defaultCertPrefix + c.certificate.Name,
})
Expand Down
44 changes: 22 additions & 22 deletions pkg/certificates/controller_test.go
Expand Up @@ -14,9 +14,9 @@ import (
"testing"

"github.com/appscode/log"
aci "github.com/appscode/voyager/api"
api "github.com/appscode/voyager/api"
acs "github.com/appscode/voyager/client/clientset"
"github.com/appscode/voyager/client/clientset/fake"
acf "github.com/appscode/voyager/client/clientset/fake"
"github.com/appscode/voyager/test/testframework"
"github.com/stretchr/testify/assert"
"github.com/xenolf/lego/acme"
Expand All @@ -30,13 +30,13 @@ func init() {
}

func TestLoadProviderCredential(t *testing.T) {
fakeController := NewController(fake.NewSimpleClientset(), fake.NewFakeExtensionClient())
fakeController.certificate = &aci.Certificate{
fakeController := NewController(fake.NewSimpleClientset(), acf.NewFakeExtensionClient())
fakeController.certificate = &api.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "bar",
},
Spec: aci.CertificateSpec{
Spec: api.CertificateSpec{
ProviderCredentialSecretName: "foosecret",
},
}
Expand Down Expand Up @@ -71,17 +71,17 @@ func TestLoadProviderCredential(t *testing.T) {

func TestEnsureClient(t *testing.T) {
if testframework.TestContext.Verbose {
fakeController := NewController(fakeclientset.NewSimpleClientset(
fakeController := NewController(fake.NewSimpleClientset(
&apiv1.Secret{
ObjectMeta: metav1.ObjectMeta{Name: "secret", Namespace: "bar"},
},
), fake.NewFakeExtensionClient())
fakeController.certificate = &aci.Certificate{
), acf.NewFakeExtensionClient())
fakeController.certificate = &api.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "bar",
},
Spec: aci.CertificateSpec{
Spec: api.CertificateSpec{
Domains: strings.Split(os.Getenv("TEST_DNS_DOMAINS"), ","),
Email: os.Getenv("TEST_ACME_USER_EMAIL"),
Provider: "googlecloud",
Expand Down Expand Up @@ -109,25 +109,25 @@ func TestEnsureClient(t *testing.T) {
assert.Nil(t, err)

fakeController.ensureACMEClient()
secret, err := fakeController.KubeClient.CoreV1().Secrets("bar").Get(defaultUserSecretPrefix + fakeController.certificate.Name)
secret, err := fakeController.KubeClient.CoreV1().Secrets("bar").Get(defaultUserSecretPrefix+fakeController.certificate.Name, metav1.GetOptions{})
assert.Nil(t, err)
assert.NotNil(t, secret)
assert.Equal(t, 1, len(secret.Data))
}
}

func TestFakeRegisterACMEUser(t *testing.T) {
fakeController := NewController(fakeclientset.NewSimpleClientset(
fakeController := NewController(fake.NewSimpleClientset(
&apiv1.Secret{
ObjectMeta: metav1.ObjectMeta{Name: "secret", Namespace: "bar"},
},
), fake.NewFakeExtensionClient())
fakeController.certificate = &aci.Certificate{
), acf.NewFakeExtensionClient())
fakeController.certificate = &api.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "bar",
},
Spec: aci.CertificateSpec{
Spec: api.CertificateSpec{
Domains: []string{"example.com"},
Email: newFakeACMEUser().email,
Provider: "googlecloud",
Expand All @@ -149,7 +149,7 @@ func TestFakeRegisterACMEUser(t *testing.T) {
err := fakeController.registerACMEUser(acmeClient)
if !assert.NotNil(t, err) {
assert.Nil(t, err)
secret, err := fakeController.KubeClient.CoreV1().Secrets("bar").Get(defaultUserSecretPrefix + fakeController.certificate.Name)
secret, err := fakeController.KubeClient.CoreV1().Secrets("bar").Get(defaultUserSecretPrefix+fakeController.certificate.Name, metav1.GetOptions{})
assert.Nil(t, err)
if assert.NotNil(t, secret) {
assert.Equal(t, 1, len(secret.Data))
Expand All @@ -160,13 +160,13 @@ func TestFakeRegisterACMEUser(t *testing.T) {

func TestCreate(t *testing.T) {
if testframework.TestContext.Verbose {
fakeController := NewController(fakeclientset.NewSimpleClientset(), fake.NewFakeExtensionClient())
fakeController.certificate = &aci.Certificate{
fakeController := NewController(fake.NewSimpleClientset(), acf.NewFakeExtensionClient())
fakeController.certificate = &api.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "bar",
},
Spec: aci.CertificateSpec{
Spec: api.CertificateSpec{
Domains: strings.Split(os.Getenv("TEST_DNS_DOMAINS"), ","),
Email: os.Getenv("TEST_ACME_USER_EMAIL"),
Provider: "googlecloud",
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestCreate(t *testing.T) {

fakeController.create()

secret, err := fakeController.KubeClient.CoreV1().Secrets("bar").Get(defaultUserSecretPrefix + fakeController.certificate.Name)
secret, err := fakeController.KubeClient.CoreV1().Secrets("bar").Get(defaultUserSecretPrefix+fakeController.certificate.Name, metav1.GetOptions{})
assert.Nil(t, err)
assert.Equal(t, len(secret.Data), 1)

Expand All @@ -208,7 +208,7 @@ func TestCreate(t *testing.T) {
}

// Check the certificate data
secret, err = fakeController.KubeClient.CoreV1().Secrets("bar").Get("cert-" + fakeController.certificate.Name)
secret, err = fakeController.KubeClient.CoreV1().Secrets("bar").Get("cert-"+fakeController.certificate.Name, metav1.GetOptions{})
assert.Nil(t, err)
if err != nil {
t.Fatal(err)
Expand All @@ -228,12 +228,12 @@ func TestCreate(t *testing.T) {
}

func TestDemoCertificates(t *testing.T) {
c := &aci.Certificate{
c := &api.Certificate{
ObjectMeta: metav1.ObjectMeta{
Name: "test-do-token",
Namespace: "default",
},
Spec: aci.CertificateSpec{
Spec: api.CertificateSpec{
Domains: []string{"john.example.com"},
Provider: "digitalocean",
Email: "john@example.com",
Expand Down
10 changes: 5 additions & 5 deletions pkg/events/types.go
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/appscode/log"
aci "github.com/appscode/voyager/api"
"github.com/appscode/voyager/api"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
apiv1 "k8s.io/client-go/pkg/api/v1"
Expand Down Expand Up @@ -163,9 +163,9 @@ func detectObjectType(o interface{}) ObjectType {
return ConfigMap
case apiv1.Endpoints, *apiv1.Endpoints:
return Endpoint
case aci.Ingress, *aci.Ingress:
case api.Ingress, *api.Ingress:
return ExtendedIngress
case aci.Certificate, *aci.Certificate:
case api.Certificate, *api.Certificate:
return Certificate
case extensions.ReplicaSet, *extensions.ReplicaSet:
return ReplicaSet
Expand Down Expand Up @@ -194,9 +194,9 @@ func objectMetadata(o interface{}, t ObjectType) metav1.ObjectMeta {
case Ingress:
return o.(*extensions.Ingress).ObjectMeta
case ExtendedIngress:
return o.(*aci.Ingress).ObjectMeta
return o.(*api.Ingress).ObjectMeta
case Certificate:
return o.(*aci.Certificate).ObjectMeta
return o.(*api.Certificate).ObjectMeta
case Endpoint:
return o.(*apiv1.Endpoints).ObjectMeta
case ReplicaSet:
Expand Down