Add unit tests on ees

This commit is contained in:
armirveliaj
2024-06-24 10:24:23 -04:00
committed by Dan Christian Bogos
parent 6df400cc7e
commit eb11b51c5e

View File

@@ -26,6 +26,7 @@ import (
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
elasticsearch "github.com/elastic/go-elasticsearch/v8"
)
func TestGetMetrics(t *testing.T) {
@@ -347,3 +348,48 @@ func TestElasticExportEvent4(t *testing.T) {
t.Errorf("Expected %q but got %q", errExpect, err)
}
}
func TestElasticClose(t *testing.T) {
elasticEE := &ElasticEE{
eClnt: &elasticsearch.Client{},
}
err := elasticEE.Close()
if elasticEE.eClnt != nil {
t.Errorf("expected eClnt to be nil, got %v", elasticEE.eClnt)
}
if err != nil {
t.Errorf("expected no error, got %v", err)
}
}
func TestElasticConnect(t *testing.T) {
t.Run("ClientAlreadyExists", func(t *testing.T) {
elasticEE := &ElasticEE{
eClnt: &elasticsearch.Client{},
}
err := elasticEE.Connect()
if err != nil {
t.Errorf("expected no error, got %v", err)
}
if elasticEE.eClnt == nil {
t.Error("expected existing client to remain initialized")
}
})
t.Run("ClientDoesNotExist", func(t *testing.T) {
elasticEE := &ElasticEE{}
err := elasticEE.Connect()
if err != nil {
t.Errorf("expected no error, got %v", err)
}
if elasticEE.eClnt == nil {
t.Error("expected client to be initialized")
}
})
}