Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding exporter test #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}

}