go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/common/bq/schema_test.go (about) 1 // Copyright 2018 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package bq 16 17 import ( 18 "testing" 19 20 "cloud.google.com/go/bigquery" 21 22 . "github.com/smartystreets/goconvey/convey" 23 ) 24 25 func TestAddMissingFields(t *testing.T) { 26 Convey("Rename field", t, func() { 27 from := bigquery.Schema{ 28 { 29 Name: "a", 30 Type: bigquery.IntegerFieldType, 31 }, 32 { 33 Name: "b", 34 Type: bigquery.RecordFieldType, 35 Schema: bigquery.Schema{ 36 { 37 Name: "c", 38 Type: bigquery.IntegerFieldType, 39 }, 40 { 41 Name: "d", 42 Type: bigquery.IntegerFieldType, 43 }, 44 }, 45 }, 46 } 47 to := bigquery.Schema{ 48 { 49 Name: "e", 50 Type: bigquery.IntegerFieldType, 51 }, 52 { 53 Name: "b", 54 Type: bigquery.RecordFieldType, 55 Schema: bigquery.Schema{ 56 { 57 Name: "c", 58 Type: bigquery.IntegerFieldType, 59 }, 60 }, 61 }, 62 } 63 AddMissingFields(&to, from) 64 So(to, ShouldResemble, bigquery.Schema{ 65 { 66 Name: "e", 67 Type: bigquery.IntegerFieldType, 68 }, 69 { 70 Name: "b", 71 Type: bigquery.RecordFieldType, 72 Schema: bigquery.Schema{ 73 { 74 Name: "c", 75 Type: bigquery.IntegerFieldType, 76 }, 77 { 78 Name: "d", 79 Type: bigquery.IntegerFieldType, 80 }, 81 }, 82 }, 83 { 84 Name: "a", 85 Type: bigquery.IntegerFieldType, 86 }, 87 }) 88 }) 89 }