Xu-Wentao commented on code in PR #286:
URL:
https://github.com/apache/shardingsphere-on-cloud/pull/286#discussion_r1155678080
##########
shardingsphere-operator/pkg/reconcile/ShardingSphereChaos/ShardingSphereChaos_suite_test.go:
##########
Review Comment:
you can use `fakeClient` to mock client.Client. below is a simple example.
```go
import (
// import other needed packages...
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
)
var fakeClient client.Client
// your new reconciler or controller
var reconciler *YourReconciler
// register some CRD or resources for your need.
scheme := runtime.NewScheme()
Expect(corev1.AddToScheme(scheme)).To(Succeed())
Expect(appsv1.AddToScheme(scheme)).To(Succeed())
fakeClient = fake.NewClientBuilder().WithScheme(scheme).Build()
reconciler = &controllers.YourController{}
req := reconcile.Request{
NamespacedName: client.ObjectKey{
Namespace: "test-namespace",
Name: "test-resource",
},
}
// create some resource if needed by fakeClient.Create()
// Expect(fakeClient.Create(context.Background(),
&appsv1.Deployment{})).To(Succeed())
// ...
res, err := reconciler.Reconcile(context.Background(), req)
Expect(err).NotTo(HaveOccurred())
// handle res if needed.
// ...
```
you can move some common code to ginkgo's `BeforeEach` and `AfterEach`.
Please help yourself.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]