From c3c258ecf3d46d6433351bb679b9a33a8c8d1f94 Mon Sep 17 00:00:00 2001 From: Divya Pamecha <21123621+Its-Maniaco@users.noreply.github.com> Date: Tue, 30 Jan 2024 18:50:22 +0530 Subject: [PATCH] adding exporter test Signed-off-by: Divya Pamecha <21123621+Its-Maniaco@users.noreply.github.com> --- controller/controller_test.go | 62 +++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 controller/controller_test.go diff --git a/controller/controller_test.go b/controller/controller_test.go new file mode 100644 index 0000000..d2b12d2 --- /dev/null +++ b/controller/controller_test.go @@ -0,0 +1,62 @@ +package controller_test + +import ( + "fmt" + "testing" + "time" + + "github.com/golang/mock/gomock" + "github.com/litmuschaos/chaos-operator/api/litmuschaos/v1alpha1" + "github.com/stretchr/testify/assert" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/litmuschaos/chaos-exporter/controller" + "github.com/litmuschaos/chaos-exporter/controller/mocks" + "github.com/litmuschaos/chaos-exporter/pkg/log" +) + +func TestExporter(t *testing.T) { + + mockClient := CreateFakeClient(t) + log.Info("Started creating Metrics") + log.Info("Registering Fixed Metrics") + + //Creating Mock MetricesCollecter + mockCtl := gomock.NewController(t) + defer mockCtl.Finish() + mockCollectData := mocks.NewMockResultCollector(mockCtl) + + r := controller.MetricesCollecter{ + ResultCollector: mockCollectData, + } + + //Chaos Result List + mockOverallChaosResults := v1alpha1.ChaosResultList{ + Items: []v1alpha1.ChaosResult{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "chaosresult-1", + }, + }, + }, + } + + // Register Register Fixed Metrics + r.GaugeMetrics.InitializeGaugeMetrics().RegisterFixedMetrics() + + // Enable Monitoring + monitoringEnabled := controller.MonitoringEnabled{ + IsChaosResultsAvailable: true, + IsChaosEnginesAvailable: true, + } + fmt.Println("Before Loop") + // Running the unit test for GetLitmusChaosMetrics + for { + assert.NoError(t, r.GetLitmusChaosMetrics(mockClient, &mockOverallChaosResults, &monitoringEnabled)) + /* + Unit test GetLitmusChaosMetrics + */ + time.Sleep(1000 * time.Millisecond) + } + +}