From eb11b51c5e4defb2954c19cf62764c408ba21e9a Mon Sep 17 00:00:00 2001 From: armirveliaj Date: Mon, 24 Jun 2024 10:24:23 -0400 Subject: [PATCH] Add unit tests on ees --- ees/elastic_test.go | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/ees/elastic_test.go b/ees/elastic_test.go index 54976dfab..8744cde1e 100644 --- a/ees/elastic_test.go +++ b/ees/elastic_test.go @@ -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") + } + }) +}