Skip to content
New issue

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

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

Already on GitHub? # to your account

fixing tests with stuff from master #230

Merged
merged 1 commit into from
Sep 23, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion api/v1/sqlserver_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ var _ = Describe("SqlServer", func() {
Spec: SqlServerSpec{
Location: "westus",
ResourceGroup: "foo-resourcegroup",
AdminUser: "iamadmin",
AllowAzureServiceAccess: true,
}}

Expand Down
16 changes: 8 additions & 8 deletions controllers/consumergroup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ var _ = Describe("ConsumerGroup Controller", func() {

BeforeEach(func() {
// Add any setup steps that needs to be executed before each test
rgName = resourceGroupName
ehnName = eventhubNamespaceName
ehName = eventhubName
rgName = tc.ResourceGroupName
ehnName = tc.EventhubNamespaceName
ehName = tc.EventhubName
})

AfterEach(func() {
Expand Down Expand Up @@ -73,27 +73,27 @@ var _ = Describe("ConsumerGroup Controller", func() {
},
}

err = k8sClient.Create(context.Background(), consumerGroupInstance)
err = tc.K8sClient.Create(context.Background(), consumerGroupInstance)
Expect(apierrors.IsInvalid(err)).To(Equal(false))
Expect(err).NotTo(HaveOccurred())

consumerGroupNamespacedName := types.NamespacedName{Name: consumerGroupName, Namespace: "default"}

Eventually(func() bool {
_ = k8sClient.Get(context.Background(), consumerGroupNamespacedName, consumerGroupInstance)
_ = tc.K8sClient.Get(context.Background(), consumerGroupNamespacedName, consumerGroupInstance)
return consumerGroupInstance.HasFinalizer(consumerGroupFinalizerName)
}, timeout,
).Should(BeTrue())

Eventually(func() bool {
_ = k8sClient.Get(context.Background(), consumerGroupNamespacedName, consumerGroupInstance)
_ = tc.K8sClient.Get(context.Background(), consumerGroupNamespacedName, consumerGroupInstance)
return consumerGroupInstance.IsSubmitted()
}, timeout,
).Should(BeTrue())

k8sClient.Delete(context.Background(), consumerGroupInstance)
tc.K8sClient.Delete(context.Background(), consumerGroupInstance)
Eventually(func() bool {
_ = k8sClient.Get(context.Background(), consumerGroupNamespacedName, consumerGroupInstance)
_ = tc.K8sClient.Get(context.Background(), consumerGroupNamespacedName, consumerGroupInstance)
return consumerGroupInstance.IsBeingDeleted()
}, timeout,
).Should(BeTrue())
Expand Down
145 changes: 115 additions & 30 deletions controllers/eventhub_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ package controllers

import (
"context"

azurev1 "github.com/Azure/azure-service-operator/api/v1"
helpers "github.com/Azure/azure-service-operator/pkg/helpers"

"github.com/Azure/azure-service-operator/pkg/helpers"
"time"

eventhubsmanager "github.com/Azure/azure-service-operator/pkg/resourcemanager/eventhubs"

. "github.com/onsi/ginkgo"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -33,15 +33,22 @@ import (
)

var _ = Describe("EventHub Controller", func() {
const timeout = time.Second * 240

const timeout = time.Second * 60

var rgName string
var rgLocation string
var ehnName string
var saName string
var bcName string

BeforeEach(func() {
// Add any setup steps that needs to be executed before each test
rgName = resourceGroupName
ehnName = eventhubNamespaceName
rgName = tc.ResourceGroupName
rgLocation = tc.ResourceGroupLocation
ehnName = tc.EventhubNamespaceName
saName = tc.StorageAccountName
bcName = tc.BlobContainerName
})

AfterEach(func() {
Expand All @@ -53,7 +60,7 @@ var _ = Describe("EventHub Controller", func() {
// Avoid adding tests for vanilla CRUD operations because they would
// test Kubernetes API server, which isn't the goal here.
Context("Create and Delete", func() {
It("should validate eventhubnamespaces exist before creating eventhubs", func() {
It("should fail to create eventhub if eventhubnamespace doesn't exist", func() {

eventhubName := "t-eh-" + helpers.RandomString(10)

Expand All @@ -69,17 +76,17 @@ var _ = Describe("EventHub Controller", func() {
ResourceGroup: "t-rg-dev-eh-" + helpers.RandomString(10),
Properties: azurev1.EventhubProperties{
MessageRetentionInDays: 7,
PartitionCount: 1,
PartitionCount: 2,
},
},
}

k8sClient.Create(context.Background(), eventhubInstance)
tc.K8sClient.Create(context.Background(), eventhubInstance)

eventhubNamespacedName := types.NamespacedName{Name: eventhubName, Namespace: "default"}

Eventually(func() bool {
_ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
_ = tc.K8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
return eventhubInstance.IsSubmitted()
}, timeout,
).Should(BeFalse())
Expand All @@ -103,7 +110,7 @@ var _ = Describe("EventHub Controller", func() {
ResourceGroup: rgName,
Properties: azurev1.EventhubProperties{
MessageRetentionInDays: 7,
PartitionCount: 1,
PartitionCount: 2,
},
AuthorizationRule: azurev1.EventhubAuthorizationRule{
Name: "RootManageSharedAccessKey",
Expand All @@ -112,20 +119,20 @@ var _ = Describe("EventHub Controller", func() {
},
}

err = k8sClient.Create(context.Background(), eventhubInstance)
err = tc.K8sClient.Create(context.Background(), eventhubInstance)
Expect(apierrors.IsInvalid(err)).To(Equal(false))
Expect(err).NotTo(HaveOccurred())

eventhubNamespacedName := types.NamespacedName{Name: eventhubName, Namespace: "default"}

Eventually(func() bool {
_ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
_ = tc.K8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
return eventhubInstance.HasFinalizer(eventhubFinalizerName)
}, timeout,
).Should(BeTrue())

Eventually(func() bool {
_ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
_ = tc.K8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
return eventhubInstance.IsSubmitted()
}, timeout,
).Should(BeTrue())
Expand All @@ -152,19 +159,19 @@ var _ = Describe("EventHub Controller", func() {
Type: "Opaque",
}

err = k8sClient.Create(context.Background(), csecret)
err = tc.K8sClient.Create(context.Background(), csecret)
Expect(err).NotTo(HaveOccurred())

//get secret from k8s
secret := &v1.Secret{}
err = k8sClient.Get(context.Background(), types.NamespacedName{Name: eventhubName, Namespace: eventhubInstance.Namespace}, secret)
err = tc.K8sClient.Get(context.Background(), types.NamespacedName{Name: eventhubName, Namespace: eventhubInstance.Namespace}, secret)
Expect(err).NotTo(HaveOccurred())
Expect(secret.Data).To(Equal(csecret.Data))
Expect(secret.ObjectMeta).To(Equal(csecret.ObjectMeta))

k8sClient.Delete(context.Background(), eventhubInstance)
tc.K8sClient.Delete(context.Background(), eventhubInstance)
Eventually(func() bool {
_ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
_ = tc.K8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
return eventhubInstance.IsBeingDeleted()
}, timeout,
).Should(BeTrue())
Expand All @@ -185,7 +192,7 @@ var _ = Describe("EventHub Controller", func() {
Namespace: "default",
},
Spec: azurev1.EventhubSpec{
Location: "westus",
Location: rgLocation,
Namespace: ehnName,
ResourceGroup: rgName,
Properties: azurev1.EventhubProperties{
Expand All @@ -200,20 +207,20 @@ var _ = Describe("EventHub Controller", func() {
},
}

err = k8sClient.Create(context.Background(), eventhubInstance)
err = tc.K8sClient.Create(context.Background(), eventhubInstance)
Expect(apierrors.IsInvalid(err)).To(Equal(false))
Expect(err).NotTo(HaveOccurred())

eventhubNamespacedName := types.NamespacedName{Name: eventhubName, Namespace: "default"}

Eventually(func() bool {
_ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
_ = tc.K8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
return eventhubInstance.HasFinalizer(eventhubFinalizerName)
}, timeout,
).Should(BeTrue())

Eventually(func() bool {
_ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
_ = tc.K8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
return eventhubInstance.IsSubmitted()
}, timeout,
).Should(BeTrue())
Expand All @@ -240,20 +247,98 @@ var _ = Describe("EventHub Controller", func() {
Type: "Opaque",
}

err = k8sClient.Create(context.Background(), csecret)
err = tc.K8sClient.Create(context.Background(), csecret)
Expect(err).NotTo(HaveOccurred())

//get secret from k8s
secret := &v1.Secret{}
err = k8sClient.Get(context.Background(), types.NamespacedName{Name: secretName, Namespace: eventhubInstance.Namespace}, secret)
secret := v1.Secret{}
Eventually(func() bool {
err = tc.K8sClient.Get(context.Background(), types.NamespacedName{Name: secretName, Namespace: eventhubInstance.Namespace}, &secret)
if err != nil {
return false
}
Expect(secret.Data).To(Equal(csecret.Data))
Expect(secret.ObjectMeta).To(Equal(csecret.ObjectMeta))
return true
}, 60).Should(BeTrue())

tc.K8sClient.Delete(context.Background(), eventhubInstance)
Eventually(func() bool {
_ = tc.K8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
return eventhubInstance.IsBeingDeleted()
}, timeout,
).Should(BeTrue())

})

It("should create and delete event hubs with capture", func() {

eventHubName := "t-eh-" + helpers.RandomString(10)

var err error

// Create the EventHub object and expect the Reconcile to be created
eventHubInstance := &azurev1.Eventhub{
ObjectMeta: metav1.ObjectMeta{
Name: eventHubName,
Namespace: "default",
},
Spec: azurev1.EventhubSpec{
Location: rgLocation,
Namespace: ehnName,
ResourceGroup: rgName,
Properties: azurev1.EventhubProperties{
MessageRetentionInDays: 7,
PartitionCount: 2,
CaptureDescription: azurev1.CaptureDescription{
Destination: azurev1.Destination{
ArchiveNameFormat: "{Namespace}/{EventHub}/{PartitionId}/{Year}/{Month}/{Day}/{Hour}/{Minute}/{Second}",
BlobContainer: bcName,
Name: "EventHubArchive.AzureBlockBlob",
StorageAccount: azurev1.StorageAccount{
ResourceGroup: rgName,
AccountName: saName,
},
},
Enabled: true,
SizeLimitInBytes: 524288000,
IntervalInSeconds: 300,
},
},
},
}

err = tc.K8sClient.Create(context.Background(), eventHubInstance)
Expect(apierrors.IsInvalid(err)).To(Equal(false))
Expect(err).NotTo(HaveOccurred())
Expect(secret.Data).To(Equal(csecret.Data))
Expect(secret.ObjectMeta).To(Equal(csecret.ObjectMeta))

k8sClient.Delete(context.Background(), eventhubInstance)
eventHubNamespacedName := types.NamespacedName{Name: eventHubName, Namespace: "default"}

Eventually(func() bool {
_ = k8sClient.Get(context.Background(), eventhubNamespacedName, eventhubInstance)
return eventhubInstance.IsBeingDeleted()
_ = tc.K8sClient.Get(context.Background(), eventHubNamespacedName, eventHubInstance)
return eventHubInstance.HasFinalizer(eventhubFinalizerName)
}, timeout,
).Should(BeTrue())

Eventually(func() bool {
_ = tc.K8sClient.Get(context.Background(), eventHubNamespacedName, eventHubInstance)
return eventHubInstance.IsSubmitted()
}, timeout,
).Should(BeTrue())

Eventually(func() bool {
hub, _ := eventhubsmanager.GetHub(context.Background(), rgName, ehnName, eventHubName)
if hub.Properties == nil || hub.CaptureDescription == nil || hub.CaptureDescription.Enabled == nil {
return false
}
return *hub.CaptureDescription.Enabled
}, timeout,
).Should(BeTrue())

tc.K8sClient.Delete(context.Background(), eventHubInstance)
Eventually(func() bool {
_ = tc.K8sClient.Get(context.Background(), eventHubNamespacedName, eventHubInstance)
return eventHubInstance.IsBeingDeleted()
}, timeout,
).Should(BeTrue())

Expand Down
Loading