@@ -3,6 +3,7 @@ package bigquery_test
3
3
import (
4
4
"testing"
5
5
6
+ "github.com/odpf/guardian/core/resource"
6
7
"github.com/odpf/guardian/domain"
7
8
"github.com/odpf/guardian/plugins/providers/bigquery"
8
9
"github.com/stretchr/testify/assert"
@@ -26,6 +27,39 @@ func TestDataSet(t *testing.T) {
26
27
URN : "p_id:d_id" ,
27
28
},
28
29
},
30
+ {
31
+ ds : & bigquery.Dataset {
32
+ ProjectID : "p_id" ,
33
+ DatasetID : "d_id" ,
34
+ Labels : nil ,
35
+ },
36
+ expectedResource : & domain.Resource {
37
+ Type : bigquery .ResourceTypeDataset ,
38
+ Name : "d_id" ,
39
+ URN : "p_id:d_id" ,
40
+ },
41
+ },
42
+ {
43
+ ds : & bigquery.Dataset {
44
+ ProjectID : "p_id" ,
45
+ DatasetID : "d_id" ,
46
+ Labels : map [string ]string {
47
+ "key1" : "value1" ,
48
+ },
49
+ },
50
+ expectedResource : & domain.Resource {
51
+ Type : bigquery .ResourceTypeDataset ,
52
+ Name : "d_id" ,
53
+ URN : "p_id:d_id" ,
54
+ Details : map [string ]interface {}{
55
+ resource .ReservedDetailsKeyMetadata : map [string ]interface {}{
56
+ "labels" : map [string ]string {
57
+ "key1" : "value1" ,
58
+ },
59
+ },
60
+ },
61
+ },
62
+ },
29
63
}
30
64
31
65
for _ , tc := range testCases {
@@ -34,6 +68,7 @@ func TestDataSet(t *testing.T) {
34
68
assert .Equal (t , tc .expectedResource .Type , actualResource .Type )
35
69
assert .Equal (t , tc .expectedResource .Name , actualResource .Name )
36
70
assert .Equal (t , tc .expectedResource .URN , actualResource .URN )
71
+ assert .Equal (t , tc .expectedResource .Details , actualResource .Details )
37
72
}
38
73
})
39
74
})
@@ -89,6 +124,41 @@ func TestTable(t *testing.T) {
89
124
URN : "p_id:d_id.t_id" ,
90
125
},
91
126
},
127
+ {
128
+ tb : & bigquery.Table {
129
+ TableID : "t_id" ,
130
+ ProjectID : "p_id" ,
131
+ DatasetID : "d_id" ,
132
+ Labels : nil ,
133
+ },
134
+ expectedResource : & domain.Resource {
135
+ Type : bigquery .ResourceTypeTable ,
136
+ Name : "t_id" ,
137
+ URN : "p_id:d_id.t_id" ,
138
+ },
139
+ },
140
+ {
141
+ tb : & bigquery.Table {
142
+ TableID : "t_id" ,
143
+ ProjectID : "p_id" ,
144
+ DatasetID : "d_id" ,
145
+ Labels : map [string ]string {
146
+ "key1" : "value1" ,
147
+ },
148
+ },
149
+ expectedResource : & domain.Resource {
150
+ Type : bigquery .ResourceTypeTable ,
151
+ Name : "t_id" ,
152
+ URN : "p_id:d_id.t_id" ,
153
+ Details : map [string ]interface {}{
154
+ resource .ReservedDetailsKeyMetadata : map [string ]interface {}{
155
+ "labels" : map [string ]string {
156
+ "key1" : "value1" ,
157
+ },
158
+ },
159
+ },
160
+ },
161
+ },
92
162
}
93
163
94
164
for _ , tc := range testCases {
@@ -97,6 +167,7 @@ func TestTable(t *testing.T) {
97
167
assert .Equal (t , tc .expectedResource .Type , actualResource .Type )
98
168
assert .Equal (t , tc .expectedResource .Name , actualResource .Name )
99
169
assert .Equal (t , tc .expectedResource .URN , actualResource .URN )
170
+ assert .Equal (t , tc .expectedResource .Details , actualResource .Details )
100
171
}
101
172
})
102
173
})
0 commit comments