-
Notifications
You must be signed in to change notification settings - Fork 204
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
add tests for controller with mock #344
Merged
priyakumarank
merged 38 commits into
Azure:master
from
priyakumarank:feat/99-SQLControllerTestsWithMock
Oct 29, 2019
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
e8ecfb8
add tests for controller with mock
4d281cc
merge from master to branch
3e6fe19
add package
485deb5
update api version in tests
6f593de
remove status update instance directly
7a78216
fix controllerutil crash in tests and move mock
c02963f
update to run mock and azure based on flag
71fc0ee
Merge branch 'master' into feat/99-SQLControllerTestsWithMock
priyakumarank 6b1b30f
Merge branch 'master' into feat/99-SQLControllerTestsWithMock
priyakumarank 81597ec
enable tests to run in parallel
e2e213b
increase timeout
55bf533
run sql controller with mock always
fdf622b
merge from master to branch
5756c4d
rename test files
3372db8
run sql with mock always
90aef7d
update test
5eb7841
Merge branch 'master' into feat/99-SQLControllerTestsWithMock
priyakumarank f3ddfdf
Merge branch 'master' into feat/99-SQLControllerTestsWithMock
priyakumarank e49f9eb
enable parallel tests
32af2b3
Merge branch 'feat/99-SQLControllerTestsWithMock' of https://github.c…
2f31e9f
run sql using mock
4a429eb
disable tests running in parallel
706887d
merge from master to branch
64e1aca
remove tests and add status subresource back
fc325eb
merge from master and fix conflicts
06b4059
add interface methods
d3dba00
update status
8a4f788
refactor gosdkclient
5dd33bd
refactor sqlclient gosdk
f777198
use resourceclient
f59f811
remove redundant file
77c8ae5
enable parallel tests
3088535
add tests and fix issues
1ca646c
merge from master to branch
c441016
disable parallel tests
11ac815
use requeue_after env variable
ca48085
Merge branch 'master' into feat/99-SQLControllerTestsWithMock
priyakumarank 52a13d6
make requeue time configurablle in eh ns
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright 2019 microsoft. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package controllers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" | ||
helpers "github.com/Azure/azure-service-operator/pkg/helpers" | ||
) | ||
|
||
const AzureSQLDatabaseFinalizerName = "azuresqldatabase.finalizers.azure.com" | ||
|
||
func (r *AzureSqlDatabaseReconciler) addFinalizer(instance *azurev1alpha1.AzureSqlDatabase) error { | ||
helpers.AddFinalizer(instance, AzureSQLDatabaseFinalizerName) | ||
if updateerr := r.Update(context.Background(), instance); updateerr != nil { | ||
r.Recorder.Event(instance, "Warning", "Failed", "Failed to update finalizer") | ||
} | ||
r.Recorder.Event(instance, "Normal", "Updated", fmt.Sprintf("finalizer %s added", AzureSQLDatabaseFinalizerName)) | ||
return nil | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
Copyright 2019 microsoft. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package controllers | ||
|
||
import ( | ||
"context" | ||
|
||
azurev1alpha1 "github.com/Azure/azure-service-operator/api/v1alpha1" | ||
|
||
helpers "github.com/Azure/azure-service-operator/pkg/helpers" | ||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
var _ = Describe("AzureSqlDatabase Controller", func() { | ||
|
||
var rgName string | ||
var rgLocation string | ||
//var sqlName string | ||
|
||
BeforeEach(func() { | ||
// Add any setup steps that needs to be executed before each test | ||
rgName = tc.resourceGroupName | ||
rgLocation = tc.resourceGroupLocation | ||
}) | ||
|
||
AfterEach(func() { | ||
// Add any teardown steps that needs to be executed after each test | ||
}) | ||
|
||
// Add Tests for OpenAPI validation (or additonal CRD features) specified in | ||
// your API definition. | ||
// 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 create and delete sql database in k8s", func() { | ||
|
||
randomName := helpers.RandomString(10) | ||
sqlServerName := "t-sqlserver-dev-" + randomName | ||
sqlDatabaseName := "t-sqldatabase-dev-" + randomName | ||
|
||
var err error | ||
|
||
// Create the SqlServer object and expect the Reconcile to be created | ||
sqlServerInstance := &azurev1alpha1.AzureSqlServer{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: sqlServerName, | ||
Namespace: "default", | ||
}, | ||
Spec: azurev1alpha1.AzureSqlServerSpec{ | ||
Location: rgLocation, | ||
ResourceGroup: rgName, | ||
}, | ||
} | ||
|
||
err = tc.k8sClient.Create(context.Background(), sqlServerInstance) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
// Create the SqlDatabase object and expect the Reconcile to be created | ||
sqlDatabaseInstance := &azurev1alpha1.AzureSqlDatabase{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: sqlDatabaseName, | ||
Namespace: "default", | ||
}, | ||
Spec: azurev1alpha1.AzureSqlDatabaseSpec{ | ||
Location: rgLocation, | ||
ResourceGroup: rgName, | ||
Server: sqlServerName, | ||
Edition: 0, | ||
}, | ||
} | ||
|
||
err = tc.k8sClient.Create(context.Background(), sqlDatabaseInstance) | ||
Expect(apierrors.IsInvalid(err)).To(Equal(false)) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
sqlDatabaseNamespacedName := types.NamespacedName{Name: sqlDatabaseName, Namespace: "default"} | ||
|
||
Eventually(func() bool { | ||
_ = tc.k8sClient.Get(context.Background(), sqlDatabaseNamespacedName, sqlDatabaseInstance) | ||
return helpers.HasFinalizer(sqlDatabaseInstance, AzureSQLDatabaseFinalizerName) | ||
}, tc.timeout, | ||
).Should(BeTrue()) | ||
|
||
Eventually(func() bool { | ||
_ = tc.k8sClient.Get(context.Background(), sqlDatabaseNamespacedName, sqlDatabaseInstance) | ||
return sqlDatabaseInstance.IsSubmitted() | ||
}, tc.timeout, | ||
).Should(BeTrue()) | ||
|
||
err = tc.k8sClient.Delete(context.Background(), sqlDatabaseInstance) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
Eventually(func() bool { | ||
_ = tc.k8sClient.Get(context.Background(), sqlDatabaseNamespacedName, sqlDatabaseInstance) | ||
return helpers.IsBeingDeleted(sqlDatabaseInstance) | ||
}, tc.timeout, | ||
).Should(BeTrue()) | ||
|
||
}) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for future reference...we have some generic functions to replace these in the helper lib.