@@ -19,10 +19,12 @@ import (
19
19
"time"
20
20
21
21
"cloud.google.com/go/internal/testutil"
22
+ "github.com/google/go-cmp/cmp"
22
23
bq "google.golang.org/api/bigquery/v2"
23
24
)
24
25
25
26
func TestBQToTableMetadata (t * testing.T ) {
27
+ bqClient := & Client {}
26
28
aTime := time .Date (2017 , 1 , 26 , 0 , 0 , 0 , 0 , time .Local )
27
29
aTimeMillis := aTime .UnixNano () / 1e6
28
30
aDurationMillis := int64 (1800000 )
@@ -76,6 +78,22 @@ func TestBQToTableMetadata(t *testing.T) {
76
78
PrimaryKey : & bq.TableConstraintsPrimaryKey {
77
79
Columns : []string {"id" },
78
80
},
81
+ ForeignKeys : []* bq.TableConstraintsForeignKeys {
82
+ {
83
+ Name : "fk" ,
84
+ ColumnReferences : []* bq.TableConstraintsForeignKeysColumnReferences {
85
+ {
86
+ ReferencedColumn : "id" ,
87
+ ReferencingColumn : "parent" ,
88
+ },
89
+ },
90
+ ReferencedTable : & bq.TableConstraintsForeignKeysReferencedTable {
91
+ DatasetId : "dataset_id" ,
92
+ ProjectId : "project_id" ,
93
+ TableId : "table_id" ,
94
+ },
95
+ },
96
+ },
79
97
},
80
98
},
81
99
& TableMetadata {
@@ -119,16 +137,32 @@ func TestBQToTableMetadata(t *testing.T) {
119
137
PrimaryKey : & PrimaryKey {
120
138
Columns : []string {"id" },
121
139
},
122
- ForeignKeys : []* ForeignKey {},
140
+ ForeignKeys : []* ForeignKey {
141
+ {
142
+ Name : "fk" ,
143
+ ReferencedTable : & Table {
144
+ c : bqClient ,
145
+ ProjectID : "project_id" ,
146
+ DatasetID : "dataset_id" ,
147
+ TableID : "table_id" ,
148
+ },
149
+ ColumnReferences : []* ColumnReference {
150
+ {
151
+ ReferencedColumn : "id" ,
152
+ ReferencingColumn : "parent" ,
153
+ },
154
+ },
155
+ },
156
+ },
123
157
},
124
158
},
125
159
},
126
160
} {
127
- got , err := bqToTableMetadata (test .in , & Client {} )
161
+ got , err := bqToTableMetadata (test .in , bqClient )
128
162
if err != nil {
129
163
t .Fatal (err )
130
164
}
131
- if diff := testutil .Diff (got , test .want ); diff != "" {
165
+ if diff := testutil .Diff (got , test .want , cmp . AllowUnexported ( Client {}, Table {}) ); diff != "" {
132
166
t .Errorf ("%+v:\n , -got, +want:\n %s" , test .in , diff )
133
167
}
134
168
}
0 commit comments