From 0fa8a621b6aff910d9cf05cc93a24adc9ff65ba4 Mon Sep 17 00:00:00 2001 From: "anjali.agarwal" Date: Thu, 5 Oct 2023 08:47:12 +0530 Subject: [PATCH] add test cases --- .../discovery_search_repository_test.go | 50 ++++++++++++------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/internal/store/elasticsearch/discovery_search_repository_test.go b/internal/store/elasticsearch/discovery_search_repository_test.go index cf387845..fd05b7cf 100644 --- a/internal/store/elasticsearch/discovery_search_repository_test.go +++ b/internal/store/elasticsearch/discovery_search_repository_test.go @@ -21,23 +21,6 @@ type searchTestData struct { func TestSearcherSearch(t *testing.T) { ctx := context.TODO() - t.Run("should return an error if search string is empty", func(t *testing.T) { - cli, err := esTestServer.NewClient() - require.NoError(t, err) - esClient, err := store.NewClient( - log.NewNoop(), - store.Config{}, - store.WithClient(cli), - ) - require.NoError(t, err) - - repo := store.NewDiscoveryRepository(esClient, log.NewNoop()) - _, err = repo.Search(ctx, asset.SearchConfig{ - Text: "", - }) - - assert.Error(t, err) - }) t.Run("fixtures", func(t *testing.T) { cli, err := esTestServer.NewClient() @@ -95,6 +78,39 @@ func TestSearcherSearch(t *testing.T) { {Type: "topic", AssetID: "transaction", Service: "rabbitmq", Data: map[string]interface{}{"company": "gotocompany", "description": "This publishes all the invoices from each of invoice storage where the invoice will be filtered and checked using invoice filterer and invoice checker", "environment": "production", "partition": float64(1), "topic_name": "transaction"}}, }, }, + { + Description: "should fetch assets with empty text", + Config: asset.SearchConfig{ + Text: "", + IncludeFields: []string{"id", "type"}, + Filters: map[string][]string{"service": {"bigquery"}}, + }, + Expected: []expectedRow{ + {Type: "table", AssetID: "bigquery::gcpproject/dataset/tablename-1"}, + {Type: "table", AssetID: "bigquery::gcpproject/dataset/tablename-common"}, + {Type: "table", AssetID: "bigquery::gcpproject/dataset/tablename-abc-common-test"}, + {Type: "table", AssetID: "bigquery::gcpproject/dataset/tablename-mid"}, + {Type: "table", AssetID: "bigquery::gcpproject/dataset/abc-tablename-mid"}, + {Type: "table", AssetID: "bigquery::gcpproject/dataset/test"}, + }, + }, + { + Description: "should fetch assets with empty text and rank by", + Config: asset.SearchConfig{ + Text: "", + RankBy: "data.profile.usage_count", + IncludeFields: []string{"id", "type"}, + Filters: map[string][]string{"service": {"bigquery"}}, + }, + Expected: []expectedRow{ + {Type: "table", AssetID: "bigquery::gcpproject/dataset/tablename-common"}, + {Type: "table", AssetID: "bigquery::gcpproject/dataset/tablename-mid"}, + {Type: "table", AssetID: "bigquery::gcpproject/dataset/test"}, + {Type: "table", AssetID: "bigquery::gcpproject/dataset/tablename-1"}, + {Type: "table", AssetID: "bigquery::gcpproject/dataset/tablename-abc-common-test"}, + {Type: "table", AssetID: "bigquery::gcpproject/dataset/abc-tablename-mid"}, + }, + }, { Description: "should fetch assets which has text in any of its fields", Config: asset.SearchConfig{