# Synceobject controller test guide - All controllers tests are to check that all the resources we expect to be created are present in the kubernetes cluster after reconcilation. - You will set up the according test variables for your own test case and then set up your synceobject, or `so` - Let's use example `TestSyncedObjectMetricsWereSet` from `controller_test.go` - For this example, first you declare function name ``` func (s *Suite) TestSyncedObjectMetricsWereSet() { } ``` - Gather metric before test: ``` const met = "edge_soctl_reconcile_condition_status" var labels = prometheus.Labels{"status": "True"} initialMetricValue := promassert.Gauge(met).With(labels).TryFold() ``` - Set up your synceobject: ``` soGUID := "guid-abc-5" so := &soapi.SyncedObject{ ObjectMeta: metav1.ObjectMeta{ Name: soGUID, Namespace: "default", }, Spec: soapi.SyncedObjectSpec{ Banner: "Foo McBar", Cluster: "Baz McClusterface", }, } ``` - Check to make sure if your `so` is ready: ``` s.Require().NoError(s.Client.Create(s.ctx, so)) s.Require().Eventually(func() bool { err := s.Client.Get(s.ctx, types.NamespacedName{ Name: so.Name, Namespace: so.Namespace, }, so) ready := conditions.IsReady(so) return err == nil && ready && hasSyncedObjectFinalizer(so) }, s.timeout, s.tick, "SyncedObject never became Ready") ``` - Lastly, check if the metric value increased by 1 after applying and reconciling the syncedobject crd. If it doesn't, return error: ``` s.Require().Eventually(func() bool { finalMetricValue := promassert.Gauge(met).With(labels).TryFold() return 1 == finalMetricValue-initialMetricValue }, s.timeout, time.Second, "Metric was never set") ``` # If you have any further question, please reach out to the platform team via #ncr-edge-api or #ncr-edge-backend :)