Skip to content

Commit

Permalink
adding exporter test
Browse files Browse the repository at this point in the history
Signed-off-by: Divya Pamecha <21123621+Its-Maniaco@users.noreply.github.com>
  • Loading branch information
Its-Maniaco committed Jan 30, 2024
1 parent fa0c4a1 commit c3c258e
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions controller/controller_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

}

0 comments on commit c3c258e

Please sign in to comment.