@@ -17,7 +17,6 @@ package bigquery
17
17
import (
18
18
"testing"
19
19
20
- "cloud.google.com/go/internal/pretty"
21
20
"cloud.google.com/go/internal/testutil"
22
21
bq "google.golang.org/api/bigquery/v2"
23
22
)
@@ -45,54 +44,130 @@ var (
45
44
)
46
45
47
46
func TestFileConfigPopulateLoadConfig (t * testing.T ) {
48
- want := & bq.JobConfigurationLoad {
49
- SourceFormat : "CSV" ,
50
- FieldDelimiter : "\t " ,
51
- SkipLeadingRows : 8 ,
52
- AllowJaggedRows : true ,
53
- AllowQuotedNewlines : true ,
54
- Autodetect : true ,
55
- Encoding : "UTF-8" ,
56
- MaxBadRecords : 7 ,
57
- IgnoreUnknownValues : true ,
58
- Schema : & bq.TableSchema {
59
- Fields : []* bq.TableFieldSchema {
60
- bqStringFieldSchema (),
61
- bqNestedFieldSchema (),
62
- }},
63
- Quote : & hyphen ,
47
+ testcases := []struct {
48
+ description string
49
+ fileConfig * FileConfig
50
+ want * bq.JobConfigurationLoad
51
+ }{
52
+ {
53
+ description : "default json" ,
54
+ fileConfig : & FileConfig {
55
+ SourceFormat : JSON ,
56
+ },
57
+ want : & bq.JobConfigurationLoad {
58
+ SourceFormat : "NEWLINE_DELIMITED_JSON" ,
59
+ },
60
+ },
61
+ {
62
+ description : "csv" ,
63
+ fileConfig : & fc ,
64
+ want : & bq.JobConfigurationLoad {
65
+ SourceFormat : "CSV" ,
66
+ FieldDelimiter : "\t " ,
67
+ SkipLeadingRows : 8 ,
68
+ AllowJaggedRows : true ,
69
+ AllowQuotedNewlines : true ,
70
+ Autodetect : true ,
71
+ Encoding : "UTF-8" ,
72
+ MaxBadRecords : 7 ,
73
+ IgnoreUnknownValues : true ,
74
+ Schema : & bq.TableSchema {
75
+ Fields : []* bq.TableFieldSchema {
76
+ bqStringFieldSchema (),
77
+ bqNestedFieldSchema (),
78
+ }},
79
+ Quote : & hyphen ,
80
+ },
81
+ },
82
+ {
83
+ description : "parquet" ,
84
+ fileConfig : & FileConfig {
85
+ SourceFormat : Parquet ,
86
+ ParquetOptions : & ParquetOptions {
87
+ EnumAsString : true ,
88
+ EnableListInference : true ,
89
+ },
90
+ },
91
+ want : & bq.JobConfigurationLoad {
92
+ SourceFormat : "PARQUET" ,
93
+ ParquetOptions : & bq.ParquetOptions {
94
+ EnumAsString : true ,
95
+ EnableListInference : true ,
96
+ },
97
+ },
98
+ },
64
99
}
65
- got := & bq.JobConfigurationLoad {}
66
- fc .populateLoadConfig (got )
67
- if ! testutil .Equal (got , want ) {
68
- t .Errorf ("got:\n %v\n want:\n %v" , pretty .Value (got ), pretty .Value (want ))
100
+ for _ , tc := range testcases {
101
+ got := & bq.JobConfigurationLoad {}
102
+ tc .fileConfig .populateLoadConfig (got )
103
+ if diff := testutil .Diff (got , tc .want ); diff != "" {
104
+ t .Errorf ("case %s, got=-, want=+:\n %s" , tc .description , diff )
105
+ }
69
106
}
70
107
}
71
108
72
109
func TestFileConfigPopulateExternalDataConfig (t * testing.T ) {
73
- got := & bq.ExternalDataConfiguration {}
74
- fc .populateExternalDataConfig (got )
75
-
76
- want := & bq.ExternalDataConfiguration {
77
- SourceFormat : "CSV" ,
78
- Autodetect : true ,
79
- MaxBadRecords : 7 ,
80
- IgnoreUnknownValues : true ,
81
- Schema : & bq.TableSchema {
82
- Fields : []* bq.TableFieldSchema {
83
- bqStringFieldSchema (),
84
- bqNestedFieldSchema (),
85
- }},
86
- CsvOptions : & bq.CsvOptions {
87
- AllowJaggedRows : true ,
88
- AllowQuotedNewlines : true ,
89
- Encoding : "UTF-8" ,
90
- FieldDelimiter : "\t " ,
91
- Quote : & hyphen ,
92
- SkipLeadingRows : 8 ,
110
+ testcases := []struct {
111
+ description string
112
+ fileConfig * FileConfig
113
+ want * bq.ExternalDataConfiguration
114
+ }{
115
+ {
116
+ description : "json defaults" ,
117
+ fileConfig : & FileConfig {
118
+ SourceFormat : JSON ,
119
+ },
120
+ want : & bq.ExternalDataConfiguration {
121
+ SourceFormat : "NEWLINE_DELIMITED_JSON" ,
122
+ },
123
+ },
124
+ {
125
+ description : "csv fileconfig" ,
126
+ fileConfig : & fc ,
127
+ want : & bq.ExternalDataConfiguration {
128
+ SourceFormat : "CSV" ,
129
+ Autodetect : true ,
130
+ MaxBadRecords : 7 ,
131
+ IgnoreUnknownValues : true ,
132
+ Schema : & bq.TableSchema {
133
+ Fields : []* bq.TableFieldSchema {
134
+ bqStringFieldSchema (),
135
+ bqNestedFieldSchema (),
136
+ }},
137
+ CsvOptions : & bq.CsvOptions {
138
+ AllowJaggedRows : true ,
139
+ AllowQuotedNewlines : true ,
140
+ Encoding : "UTF-8" ,
141
+ FieldDelimiter : "\t " ,
142
+ Quote : & hyphen ,
143
+ SkipLeadingRows : 8 ,
144
+ },
145
+ },
146
+ },
147
+ {
148
+ description : "parquet" ,
149
+ fileConfig : & FileConfig {
150
+ SourceFormat : Parquet ,
151
+ ParquetOptions : & ParquetOptions {
152
+ EnumAsString : true ,
153
+ EnableListInference : true ,
154
+ },
155
+ },
156
+ want : & bq.ExternalDataConfiguration {
157
+ SourceFormat : "PARQUET" ,
158
+ ParquetOptions : & bq.ParquetOptions {
159
+ EnumAsString : true ,
160
+ EnableListInference : true ,
161
+ },
162
+ },
93
163
},
94
164
}
95
- if diff := testutil .Diff (got , want ); diff != "" {
96
- t .Errorf ("got=-, want=+:\n %s" , diff )
165
+ for _ , tc := range testcases {
166
+ got := & bq.ExternalDataConfiguration {}
167
+ tc .fileConfig .populateExternalDataConfig (got )
168
+ if diff := testutil .Diff (got , tc .want ); diff != "" {
169
+ t .Errorf ("case %s, got=-, want=+:\n %s" , tc .description , diff )
170
+ }
97
171
}
172
+
98
173
}
0 commit comments