@@ -34,28 +34,28 @@ func TestBigQueryTableSchemaDiffSuppress(t *testing.T) {
3434 ExpectDiffSuppress : false ,
3535 },
3636 "no change" : {
37- Old : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" finalKey\" : {} }]" ,
38- New : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" finalKey\" : {} }]" ,
37+ Old : "[{\" name\" : \" someValue\" , \" type \" : \" INT64 \" , \" anotherKey\" : \" anotherValue\" , \" finalKey\" : {} }]" ,
38+ New : "[{\" name\" : \" someValue\" , \" type \" : \" INT64 \" , \" anotherKey\" : \" anotherValue\" , \" finalKey\" : {} }]" ,
3939 ExpectDiffSuppress : true ,
4040 },
4141 "remove key" : {
42- Old : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" finalKey\" : {} }]" ,
43- New : "[{\" name\" : \" someValue\" , \" finalKey\" : {} }]" ,
42+ Old : "[{\" name\" : \" someValue\" , \" type \" : \" INT64 \" , \" anotherKey\" : \" anotherValue\" , \" finalKey\" : {} }]" ,
43+ New : "[{\" name\" : \" someValue\" , \" type \" : \" INT64 \" , \" finalKey\" : {} }]" ,
4444 ExpectDiffSuppress : false ,
4545 },
4646 "empty description -> default description (empty)" : {
47- Old : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" description\" : \" \" }]" ,
48- New : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" }]" ,
47+ Old : "[{\" name\" : \" someValue\" , \" type \" : \" INT64 \" , \" anotherKey\" : \" anotherValue\" , \" description\" : \" \" }]" ,
48+ New : "[{\" name\" : \" someValue\" , \" type \" : \" INT64 \" , \" anotherKey\" : \" anotherValue\" }]" ,
4949 ExpectDiffSuppress : true ,
5050 },
5151 "empty description -> other description" : {
52- Old : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" description\" : \" \" }]" ,
53- New : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" description\" : \" somethingRandom\" }]" ,
52+ Old : "[{\" name\" : \" someValue\" , \" type \" : \" INT64 \" , \" anotherKey\" : \" anotherValue\" , \" description\" : \" \" }]" ,
53+ New : "[{\" name\" : \" someValue\" , \" type \" : \" INT64 \" , \" anotherKey\" : \" anotherValue\" , \" description\" : \" somethingRandom\" }]" ,
5454 ExpectDiffSuppress : false ,
5555 },
5656 "mode NULLABLE -> other mode" : {
57- Old : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" mode\" : \" NULLABLE\" }]" ,
58- New : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" mode\" : \" somethingRandom\" }]" ,
57+ Old : "[{\" name\" : \" someValue\" , \" type \" : \" INT64 \" , \" anotherKey\" : \" anotherValue\" , \" mode\" : \" NULLABLE\" }]" ,
58+ New : "[{\" name\" : \" someValue\" , \" type \" : \" INT64 \" , \" anotherKey\" : \" anotherValue\" , \" mode\" : \" somethingRandom\" }]" ,
5959 ExpectDiffSuppress : false ,
6060 },
6161 "mode NULLABLE -> default mode (also NULLABLE)" : {
@@ -74,6 +74,23 @@ func TestBigQueryTableSchemaDiffSuppress(t *testing.T) {
7474 ]` ,
7575 ExpectDiffSuppress : true ,
7676 },
77+ "mode & type uppercase -> lowercase" : {
78+ Old : `[
79+ {
80+ "mode": "NULLABLE",
81+ "name": "PageNo",
82+ "type": "INTEGER"
83+ }
84+ ]` ,
85+ New : `[
86+ {
87+ "mode": "nullable",
88+ "name": "PageNo",
89+ "type": "integer"
90+ }
91+ ]` ,
92+ ExpectDiffSuppress : true ,
93+ },
7794 "type INTEGER -> INT64" : {
7895 Old : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" type\" : \" INTEGER\" }]" ,
7996 New : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" type\" : \" INT64\" }]" ,
@@ -89,18 +106,32 @@ func TestBigQueryTableSchemaDiffSuppress(t *testing.T) {
89106 New : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" type\" : \" FLOAT64\" }]" ,
90107 ExpectDiffSuppress : true ,
91108 },
92- "type FLOAT -> default " : {
109+ "type FLOAT -> other " : {
93110 Old : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" type\" : \" FLOAT\" }]" ,
94- New : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" }]" ,
111+ New : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" type \" : \" somethingRandom \" }]" ,
95112 ExpectDiffSuppress : false ,
96113 },
97114 "type BOOLEAN -> BOOL" : {
98115 Old : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" type\" : \" BOOLEAN\" }]" ,
99116 New : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" type\" : \" BOOL\" }]" ,
100117 ExpectDiffSuppress : true ,
101118 },
102- "type BOOLEAN -> default " : {
119+ "type BOOLEAN -> other " : {
103120 Old : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" type\" : \" BOOLEAN\" }]" ,
121+ New : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" type\" : \" somethingRandom\" }]" ,
122+ ExpectDiffSuppress : false ,
123+ },
124+ // this is invalid but we need to make sure we don't cause a panic
125+ // if users provide an invalid schema
126+ "invalid - missing type for old" : {
127+ Old : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" }]" ,
128+ New : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" type\" : \" BOOLEAN\" }]" ,
129+ ExpectDiffSuppress : false ,
130+ },
131+ // this is invalid but we need to make sure we don't cause a panic
132+ // if users provide an invalid schema
133+ "invalid - missing type for new" : {
134+ Old : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" type\" : \" BOOLEAN\" }]" ,
104135 New : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" }]" ,
105136 ExpectDiffSuppress : false ,
106137 },
@@ -341,6 +372,7 @@ func TestBigQueryTableSchemaDiffSuppress(t *testing.T) {
341372 }
342373
343374 for tn , tc := range cases {
375+ tn := tn
344376 tc := tc
345377 t .Run (tn , func (t * testing.T ) {
346378 t .Parallel ()
@@ -1037,6 +1069,22 @@ var testUnitBigQueryDataTableIsChangableTestCases = []testUnitBigQueryDataTableJ
10371069 jsonNew : "[{\" name\" : \" someValue\" , \" type\" : \" DATETIME\" , \" mode\" : \" NULLABLE\" , \" description\" : \" some new value\" }]" ,
10381070 changeable : false ,
10391071 },
1072+ // this is invalid but we need to make sure we don't cause a panic
1073+ // if users provide an invalid schema
1074+ {
1075+ name : "typeChangeIgnoreNewMissingType" ,
1076+ jsonOld : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" }]" ,
1077+ jsonNew : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" type\" : \" BOOLEAN\" }]" ,
1078+ changeable : true ,
1079+ },
1080+ // this is invalid but we need to make sure we don't cause a panic
1081+ // if users provide an invalid schema
1082+ {
1083+ name : "typeChangeIgnoreOldMissingType" ,
1084+ jsonOld : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" }]" ,
1085+ jsonNew : "[{\" name\" : \" someValue\" , \" anotherKey\" : \" anotherValue\" , \" type\" : \" BOOLEAN\" }]" ,
1086+ changeable : true ,
1087+ },
10401088 {
10411089 name : "typeModeReqToNull" ,
10421090 jsonOld : "[{\" name\" : \" someValue\" , \" type\" : \" BOOLEAN\" , \" mode\" : \" REQUIRED\" , \" description\" : \" someVal\" }]" ,
@@ -1050,10 +1098,10 @@ var testUnitBigQueryDataTableIsChangableTestCases = []testUnitBigQueryDataTableJ
10501098 changeable : false ,
10511099 },
10521100 {
1053- name : "typeModeOmission " ,
1101+ name : "modeToDefaultNullable " ,
10541102 jsonOld : "[{\" name\" : \" someValue\" , \" type\" : \" BOOLEAN\" , \" mode\" : \" REQUIRED\" , \" description\" : \" someVal\" }]" ,
10551103 jsonNew : "[{\" name\" : \" someValue\" , \" type\" : \" BOOLEAN\" , \" description\" : \" some new value\" }]" ,
1056- changeable : false ,
1104+ changeable : true ,
10571105 },
10581106 {
10591107 name : "orderOfArrayChangesAndDescriptionChanges" ,
@@ -1822,8 +1870,8 @@ resource "google_bigquery_table" "test" {
18221870 {
18231871 description = "Time snapshot was taken, in Epoch milliseconds. Same across all rows and all tables in the snapshot, and uniquely defines a particular snapshot."
18241872 name = "snapshot_timestamp"
1825- mode = "NULLABLE "
1826- type = "INTEGER "
1873+ mode = "nullable "
1874+ type = "integer "
18271875 },
18281876 {
18291877 description = "Timestamp of dataset creation"
0 commit comments