-
Notifications
You must be signed in to change notification settings - Fork 385
New controller tests #2580
New controller tests #2580
Conversation
/hold |
Hi @piotrmiskiewicz. Thanks for your PR. I'm waiting for a kubernetes-incubator or kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
9619dfc
to
26c3f56
Compare
22bc3fe
to
e1732b0
Compare
/ok-to-test |
pkg/controller/flow_test.go
Outdated
ct.AssertOSBBasicAuth(t, "user1", "p2sswd") | ||
ct.AssertClusterServiceClassAndPlan(t) | ||
|
||
// uncomment when the https://github.com/kubernetes-incubator/service-catalog/issues/2563 is fixed |
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.
comment still valid?
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.
the comment removed
pkg/controller/case_test.go
Outdated
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: testNamespace, | ||
Name: testBindingName, | ||
Generation: 1, // set by the Webhook |
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.
misleading comment. It's not set by webhook. The main k8s server is doing that.
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.
you are right, removed
pkg/controller/case_test.go
Outdated
} | ||
} | ||
|
||
func (ct *ControllerTest) createClusterServiceBroker() *v1beta1.ClusterServiceBroker { |
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.
IMO is misleading:
you have function called createClusterServiceBroker
which is returning fixture and also CreateSimpleClusterServiceBroker
which is calling k8s Create function. Maybe the first one should be called just fixClusterServiceBroker
? U already using that for other func e.g. fixCatalogResponse
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.
renamed
pkg/controller/case_test.go
Outdated
} | ||
|
||
func (ct *ControllerTest) CreateSimpleClusterServiceBroker() { | ||
ct.scInterface.ClusterServiceBrokers().Create(ct.createClusterServiceBroker()) |
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.
why you are not returning the error? it can be important in test to assert that. I know that is a fake client but still, it can produce an error (e.g. when u add ProxyReactor)
This comment applies for all Create*
functions
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.
ok, I've added error to methods Create*
@@ -0,0 +1,583 @@ | |||
/* |
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.
IMO we should add some information/table which will show us what kind of test your PR covers.
Right now it's hard to me check what test was already replaced with the new approach.
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.
added a table with such information to the description of the PR
pkg/controller/flow_test.go
Outdated
// THEN | ||
assert.NoError(t, ct.WaitForReadyInstance()) | ||
|
||
// uncomment when the https://github.com/kubernetes-incubator/service-catalog/issues/2563 is fixed |
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.
what should be uncommented? Is that Comment still valid?
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.
removed
pkg/controller/flow_test.go
Outdated
@@ -0,0 +1,182 @@ | |||
/* | |||
Copyright 2018 The Kubernetes Authors. |
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.
Copyright 2018 The Kubernetes Authors. | |
Copyright 2019 The Kubernetes Authors. |
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.
fixed
pkg/controller/flow_test.go
Outdated
@@ -0,0 +1,182 @@ | |||
/* |
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.
IMO the filename is too generic. Could u precise the flow_test
? it's scoped for binding only if yes, then what kind of flow u test? The binding_auth_flow_test.go
will be ok name?
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.
I've renamed it to controller_flow_test. The best name would be jsut controller_test but it is used by existing unit tests.
pkg/controller/flow_test.go
Outdated
} | ||
|
||
func TestServiceBindingFailure(t *testing.T) { | ||
ct := NewControllerTest(t) |
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.
if u want to have that consistent then u miss the // GIVEN
comment
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.
added
pkg/controller/flow_test.go
Outdated
} | ||
|
||
func TestServiceBindingRetryForNonExistingClass(t *testing.T) { | ||
ct := NewControllerTest(t) |
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.
if u want to have that consistent then u miss the // GIVEN
comment
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.
added
b95ff0c
to
1e934ed
Compare
/hold cancel |
4ab57b8
to
632d019
Compare
some general comments:
|
0b9f6ce
to
5b6f645
Compare
I've added comments to test methods. Current integration tests are testing all logic implemented in the controller and API Server. I didn't wanted to remove it until we decide (and do) what should be moved to e2e tests. New controller tests are not testing validations/defaults implemented in API Server or Webhooks (in CRD solution). If you think we can remove current integration tests which are migrated - we can do that. I didn't want to decrease the coverage. In my opinion the e2e test must cover basic scenario(s) which touches all parts, for example: creates a resource with only necessary fields (all defaults are filled by webhooks), validations (then we are sure such webhooks are executed). On the other hand I don't think we need to check in e2e test like orphan mitigation scenario, retries etc. The next step would be to add necessary cases to e2e test. |
pkg/controller/case_test.go
Outdated
stopCh chan struct{} | ||
} | ||
|
||
func NewControllerTest(t *testing.T) *ControllerTest { |
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.
I think the helper methods in here should be commented as well
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.
we do not need to have it public, I've renamed it to newControllerTest
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.
I mean, i would still want them commented so someone new coming in can know what they do and how to use them
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.
ok, I put comments
pkg/controller/case_test.go
Outdated
} | ||
} | ||
|
||
func (ct *ControllerTest) fixClusterServiceBroker() *v1beta1.ClusterServiceBroker { |
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.
I don't understand why this is called "fix"? It looks to me like it's just making a basic example broker.
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.
It is a fixture. It is not a best idea to call it createXXX because "CreateXXX" methods creates an object in k8s (fake clients).
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.
ah that makes sense. I would change the name to fixtureXXX then.
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.
changed
|
||
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1" | ||
fakesc "github.com/kubernetes-incubator/service-catalog/pkg/client/clientset_generated/clientset/fake" | ||
scinterface "github.com/kubernetes-incubator/service-catalog/pkg/client/clientset_generated/clientset/typed/servicecatalog/v1beta1" |
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.
I guess 'scinterface' is a better name than 'v1beta1', but I was super confused until I realized you had renamed this import
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.
there is another v1bet1 and I had to rename it
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.
👍
/test pull-service-catalog-xbuild |
a5403b9
to
ea0556e
Compare
/test pull-service-catalog-unit |
/test pull-service-catalog-integration |
/lgtm |
could we move the chart over to an issue so we can keep track of which tests have been migrated moving foward? |
Table needs to move to issue or be encoded in the source. Best case is that this takes the integration tests down to the level without an apiserver. |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: MHBauer The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
* New controller tests (#2580) * Fix fmt issues * Add missing comments, add missing gitignore rule
This PR is a
What this PR does / why we need it:
This PR introduces controller tests, which will replace integration test after migration to CRDs. All new tests can be run with an existing implementation (API Server) because it tests only the controller. The main difference between existing controller unit tests and new tests is the unit tests are testing the reconcileXXX method. New tests are testing the controller as a black box, but do not need to start API Server. After the migration to CRDs - current integration tests will be removed.
This PR provides first part of migrated tests, see the table:
TestBasicFlow/async instances with multiple polls
TestBasicFlow/async instances with multiple polls
Which issue(s) this PR fixes
Resolves: kyma-project/kyma#2840
Please leave this checklist in the PR comment so that maintainers can ensure a good PR.
Merge Checklist:
breaking the chart release and existing clients who provide a
flag that will get an error when they try to update