...
1# Synceobject controller test guide
2
3- All controllers tests are to check that all the resources we expect to be created are present in the kubernetes cluster after reconcilation.
4- You will set up the according test variables for your own test case and then set up your synceobject, or `so`
5- Let's use example `TestSyncedObjectMetricsWereSet` from `controller_test.go`
6
7- For this example, first you declare function name
8
9```
10func (s *Suite) TestSyncedObjectMetricsWereSet() {
11
12}
13```
14
15- Gather metric before test:
16
17```
18 const met = "edge_soctl_reconcile_condition_status"
19 var labels = prometheus.Labels{"status": "True"}
20 initialMetricValue := promassert.Gauge(met).With(labels).TryFold()
21```
22
23- Set up your synceobject:
24
25```
26 soGUID := "guid-abc-5"
27 so := &soapi.SyncedObject{
28 ObjectMeta: metav1.ObjectMeta{
29 Name: soGUID,
30 Namespace: "default",
31 },
32 Spec: soapi.SyncedObjectSpec{
33 Banner: "Foo McBar",
34 Cluster: "Baz McClusterface",
35 },
36 }
37```
38
39- Check to make sure if your `so` is ready:
40
41```
42 s.Require().NoError(s.Client.Create(s.ctx, so))
43 s.Require().Eventually(func() bool {
44 err := s.Client.Get(s.ctx, types.NamespacedName{
45 Name: so.Name,
46 Namespace: so.Namespace,
47 }, so)
48 ready := conditions.IsReady(so)
49 return err == nil && ready && hasSyncedObjectFinalizer(so)
50 }, s.timeout, s.tick, "SyncedObject never became Ready")
51```
52
53- Lastly, check if the metric value increased by 1 after applying and reconciling the syncedobject crd. If it doesn't, return error:
54
55```
56 s.Require().Eventually(func() bool {
57 finalMetricValue := promassert.Gauge(met).With(labels).TryFold()
58 return 1 == finalMetricValue-initialMetricValue
59 }, s.timeout, time.Second, "Metric was never set")
60```
61
62
63# If you have any further question, please reach out to the platform team via #ncr-edge-api or #ncr-edge-backend :)
View as plain text