Skip to content

Commit

Permalink
fixing tests with stuff from master
Browse files Browse the repository at this point in the history
  • Loading branch information
frodopwns committed Oct 10, 2019
1 parent dfa43be commit 19b4e2d
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 27 deletions.
106 changes: 93 additions & 13 deletions controllers/eventhub_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package controllers

import (
"context"

azurev1 "github.com/Azure/azure-service-operator/api/v1"
"github.com/Azure/azure-service-operator/pkg/helpers"
. "github.com/onsi/ginkgo"
Expand All @@ -38,7 +37,10 @@ var _ = Describe("EventHub Controller", func() {
var bcName string

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
Expand Down Expand Up @@ -366,7 +368,7 @@ var _ = Describe("EventHub Controller", func() {
Namespace: "default",
},
Spec: azurev1.EventhubSpec{
Location: "westus",
Location: rgLocation,
Namespace: ehnName,
ResourceGroup: rgName,
Properties: azurev1.EventhubProperties{
Expand All @@ -381,20 +383,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 @@ -421,23 +423,101 @@ 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)
Expect(err).NotTo(HaveOccurred())
Expect(secret.Data).To(Equal(csecret.Data))
Expect(secret.ObjectMeta).To(Equal(csecret.ObjectMeta))
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())

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())

})

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())

eventHubNamespacedName := types.NamespacedName{Name: eventHubName, Namespace: "default"}

Eventually(func() bool {
_ = 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())

})
})
})
1 change: 1 addition & 0 deletions controllers/eventhubnamespace_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ var _ = Describe("EventHubNamespace Controller", func() {
})

It("should create and delete namespace in k8s", func() {

eventhubNamespaceName := "t-ns-dev-eh-" + helpers.RandomString(10)

var err error
Expand Down
27 changes: 13 additions & 14 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import (
"github.com/Azure/azure-service-operator/pkg/helpers"
"k8s.io/client-go/rest"

helpers "github.com/Azure/azure-service-operator/pkg/helpers"
"github.com/Azure/azure-service-operator/pkg/helpers"
"github.com/Azure/azure-service-operator/pkg/resourcemanager/storages"
"k8s.io/client-go/rest"

azurev1 "github.com/Azure/azure-service-operator/api/v1"
resourcemanagerconfig "github.com/Azure/azure-service-operator/pkg/resourcemanager/config"
Expand All @@ -49,6 +51,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -85,12 +89,7 @@ var tc testContext
func TestAPIs(t *testing.T) {
t.Parallel()
RegisterFailHandler(Fail)
resourceGroupName = "t-rg-dev-controller-" + helpers.RandomString(10)
resourcegroupLocation = "westus"

eventhubNamespaceName = "t-ns-dev-eh-ns-" + helpers.RandomString(10)
eventhubName = "t-eh-dev-sample-" + helpers.RandomString(10)
namespaceLocation = "westus"
RunSpecsWithDefaultAndCustomReporters(t,
"Controller Suite",
[]Reporter{envtest.NewlineReporter{}})
Expand All @@ -117,16 +116,16 @@ var _ = BeforeSuite(func() {

var timeout time.Duration

resoucegroupsconfig.ParseEnvironment()
resourceGroupName = "t-rg-dev-controller-" + helpers.RandomString(10)
resourcegroupLocation = resoucegroupsconfig.DefaultLocation()
resourcemanagerconfig.ParseEnvironment()
resourceGroupName := "t-rg-dev-controller-" + helpers.RandomString(10)
resourcegroupLocation := resourcemanagerconfig.DefaultLocation()

eventhubNamespaceName = "t-ns-dev-eh-ns-" + helpers.RandomString(10)
eventhubName = "t-eh-dev-sample-" + helpers.RandomString(10)
namespaceLocation = resoucegroupsconfig.DefaultLocation()
eventhubNamespaceName := "t-ns-dev-eh-ns-" + helpers.RandomString(10)
eventhubName := "t-eh-dev-sample-" + helpers.RandomString(10)
namespaceLocation := resourcemanagerconfig.DefaultLocation()

storageAccountName = "tsadeveh" + helpers.RandomString(10)
blobContainerName = "t-bc-dev-eh-" + helpers.RandomString(10)
storageAccountName := "tsadeveh" + helpers.RandomString(10)
blobContainerName := "t-bc-dev-eh-" + helpers.RandomString(10)

By("bootstrapping test environment")
testEnv = &envtest.Environment{
Expand Down

0 comments on commit 19b4e2d

Please sign in to comment.