@@ -14,7 +14,10 @@ import (
1414)
1515
1616func TestDiscoveryRepositoryUpsert (t * testing.T ) {
17- ctx := context .Background ()
17+ var (
18+ ctx = context .Background ()
19+ bigqueryService = "bigquery-test"
20+ )
1821
1922 t .Run ("should return error if id empty" , func (t * testing.T ) {
2023 cli , err := esTestServer .NewClient ()
@@ -28,8 +31,9 @@ func TestDiscoveryRepositoryUpsert(t *testing.T) {
2831
2932 repo := store .NewDiscoveryRepository (esClient )
3033 err = repo .Upsert (ctx , asset.Asset {
31- ID : "" ,
32- Type : asset .TypeTable ,
34+ ID : "" ,
35+ Type : asset .TypeTable ,
36+ Service : bigqueryService ,
3337 })
3438 assert .ErrorIs (t , err , asset .ErrEmptyID )
3539 })
@@ -46,18 +50,19 @@ func TestDiscoveryRepositoryUpsert(t *testing.T) {
4650
4751 repo := store .NewDiscoveryRepository (esClient )
4852 err = repo .Upsert (ctx , asset.Asset {
49- ID : "sample-id" ,
50- Type : asset .Type ("unknown-type" ),
53+ ID : "sample-id" ,
54+ Type : asset .Type ("unknown-type" ),
55+ Service : bigqueryService ,
5156 })
5257 assert .ErrorIs (t , err , asset .ErrUnknownType )
5358 })
5459
55- t .Run ("should insert asset to the correct index by its type " , func (t * testing.T ) {
60+ t .Run ("should insert asset to the correct index by its service " , func (t * testing.T ) {
5661 ast := asset.Asset {
5762 ID : "sample-id" ,
5863 URN : "sample-urn" ,
5964 Type : asset .TypeTable ,
60- Service : "bigquery" ,
65+ Service : bigqueryService ,
6166 Name : "sample-name" ,
6267 Description : "sample-description" ,
6368 Data : map [string ]interface {}{
@@ -85,7 +90,7 @@ func TestDiscoveryRepositoryUpsert(t *testing.T) {
8590 err = repo .Upsert (ctx , ast )
8691 assert .NoError (t , err )
8792
88- res , err := cli .API .Get ("table" , ast .ID )
93+ res , err := cli .API .Get (bigqueryService , ast .ID )
8994 require .NoError (t , err )
9095 require .False (t , res .IsError ())
9196
@@ -112,7 +117,7 @@ func TestDiscoveryRepositoryUpsert(t *testing.T) {
112117 ID : "existing-id" ,
113118 URN : "existing-urn" ,
114119 Type : asset .TypeTable ,
115- Service : "bigquery" ,
120+ Service : bigqueryService ,
116121 Name : "existing-name" ,
117122 Description : "existing-description" ,
118123 }
@@ -137,7 +142,7 @@ func TestDiscoveryRepositoryUpsert(t *testing.T) {
137142 err = repo .Upsert (ctx , newAsset )
138143 assert .NoError (t , err )
139144
140- res , err := cli .API .Get ("table" , existingAsset .ID )
145+ res , err := cli .API .Get (bigqueryService , existingAsset .ID )
141146 require .NoError (t , err )
142147 require .False (t , res .IsError ())
143148
@@ -155,7 +160,10 @@ func TestDiscoveryRepositoryUpsert(t *testing.T) {
155160}
156161
157162func TestDiscoveryRepositoryDelete (t * testing.T ) {
158- ctx := context .Background ()
163+ var (
164+ ctx = context .Background ()
165+ bigqueryService = "bigquery-test"
166+ )
159167
160168 t .Run ("should return error if id empty" , func (t * testing.T ) {
161169 cli , err := esTestServer .NewClient ()
@@ -174,9 +182,10 @@ func TestDiscoveryRepositoryDelete(t *testing.T) {
174182
175183 t .Run ("should not return error on success" , func (t * testing.T ) {
176184 ast := asset.Asset {
177- ID : "delete-id" ,
178- Type : asset .TypeTable ,
179- URN : "some-urn" ,
185+ ID : "delete-id" ,
186+ Type : asset .TypeTable ,
187+ Service : bigqueryService ,
188+ URN : "some-urn" ,
180189 }
181190
182191 cli , err := esTestServer .NewClient ()
@@ -199,7 +208,10 @@ func TestDiscoveryRepositoryDelete(t *testing.T) {
199208}
200209
201210func TestDiscoveryRepositoryGetTypes (t * testing.T ) {
202- ctx := context .Background ()
211+ var (
212+ ctx = context .Background ()
213+ bigqueryService = "bigquery-test"
214+ )
203215
204216 t .Run ("should return empty map if no type is available" , func (t * testing.T ) {
205217 cli , err := esTestServer .NewClient ()
@@ -218,8 +230,7 @@ func TestDiscoveryRepositoryGetTypes(t *testing.T) {
218230 assert .Equal (t , map [asset.Type ]int {}, counts )
219231 })
220232
221- t .Run ("should return map with 0 count if type has not been populated yet" , func (t * testing.T ) {
222- typ := asset .TypeTable
233+ t .Run ("should return empty map if type has not been populated yet" , func (t * testing.T ) {
223234 cli , err := esTestServer .NewClient ()
224235 require .NoError (t , err )
225236 esClient , err := store .NewClient (
@@ -229,25 +240,27 @@ func TestDiscoveryRepositoryGetTypes(t *testing.T) {
229240 )
230241 require .NoError (t , err )
231242
232- err = esClient .Migrate (ctx , typ )
243+ err = esClient .CreateIdx (ctx , bigqueryService )
233244 require .NoError (t , err )
234245
235246 repo := store .NewDiscoveryRepository (esClient )
236247 counts , err := repo .GetTypes (ctx )
237248 require .NoError (t , err )
238249
239- expected := map [asset.Type ]int {
240- asset .TypeTable : 0 ,
241- }
250+ expected := map [asset.Type ]int {}
242251 assert .Equal (t , expected , counts )
243252 })
244253
245254 t .Run ("should return maps of asset count with valid type as its key" , func (t * testing.T ) {
246- typ := asset .TypeDashboard
255+ var (
256+ typ = asset .TypeDashboard
257+ tableauService = "tableau-test"
258+ )
259+
247260 assets := []asset.Asset {
248- {ID : "id-asset-1" , URN : "asset-1" , Name : "asset-1" , Type : typ },
249- {ID : "id-asset-2" , URN : "asset-2" , Name : "asset-2" , Type : typ },
250- {ID : "id-asset-3" , URN : "asset-3" , Name : "asset-3" , Type : typ },
261+ {ID : "id-asset-1" , URN : "asset-1" , Name : "asset-1" , Type : typ , Service : tableauService },
262+ {ID : "id-asset-2" , URN : "asset-2" , Name : "asset-2" , Type : typ , Service : tableauService },
263+ {ID : "id-asset-3" , URN : "asset-3" , Name : "asset-3" , Type : typ , Service : tableauService },
251264 }
252265
253266 cli , err := esTestServer .NewClient ()
@@ -259,13 +272,6 @@ func TestDiscoveryRepositoryGetTypes(t *testing.T) {
259272 )
260273 require .NoError (t , err )
261274
262- err = esClient .Migrate (ctx , asset .TypeDashboard )
263- require .NoError (t , err )
264-
265- invalidType := "invalid-type"
266- err = esClient .Migrate (ctx , asset .Type (invalidType ))
267- require .NoError (t , err )
268-
269275 repo := store .NewDiscoveryRepository (esClient )
270276 _ , err = repo .GetTypes (ctx )
271277 require .NoError (t , err )
0 commit comments