1// Copyright 2019 Google LLC 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 15package bigquery 16 17import ( 18 "testing" 19 20 "cloud.google.com/go/internal/testutil" 21 bq "google.golang.org/api/bigquery/v2" 22) 23 24func TestBQToStandardSQLDataType(t *testing.T) { 25 for _, test := range []struct { 26 in *bq.StandardSqlDataType 27 want *StandardSQLDataType 28 }{ 29 {&bq.StandardSqlDataType{}, &StandardSQLDataType{}}, 30 { 31 &bq.StandardSqlDataType{ 32 TypeKind: "INT64", 33 }, 34 &StandardSQLDataType{ 35 TypeKind: "INT64", 36 }, 37 }, 38 { 39 &bq.StandardSqlDataType{ 40 TypeKind: "ARRAY", 41 ArrayElementType: &bq.StandardSqlDataType{ 42 TypeKind: "INT64", 43 }, 44 }, 45 &StandardSQLDataType{ 46 TypeKind: "ARRAY", 47 ArrayElementType: &StandardSQLDataType{ 48 TypeKind: "INT64", 49 }, 50 }, 51 }, 52 } { 53 got, err := bqToStandardSQLDataType(test.in) 54 if err != nil { 55 t.Fatal(err) 56 } 57 if diff := testutil.Diff(got, test.want); diff != "" { 58 t.Errorf("%+v: -got, +want:\n%s", test.in, diff) 59 } 60 } 61} 62 63func TestBQToStandardSQLField(t *testing.T) { 64 for _, test := range []struct { 65 in *bq.StandardSqlField 66 want *StandardSQLField 67 }{ 68 {&bq.StandardSqlField{}, &StandardSQLField{}}, 69 { 70 &bq.StandardSqlField{ 71 Name: "foo", 72 Type: &bq.StandardSqlDataType{ 73 TypeKind: "NUMERIC", 74 }, 75 }, 76 &StandardSQLField{ 77 Name: "foo", 78 Type: &StandardSQLDataType{ 79 TypeKind: "NUMERIC", 80 }, 81 }, 82 }, 83 } { 84 got, err := bqToStandardSQLField(test.in) 85 if err != nil { 86 t.Fatal(err) 87 } 88 if diff := testutil.Diff(got, test.want); diff != "" { 89 t.Errorf("%+v: -got, +want:\n%s", test.in, diff) 90 } 91 } 92} 93 94func TestBQToStandardSQLStructType(t *testing.T) { 95 for _, test := range []struct { 96 in *bq.StandardSqlStructType 97 want *StandardSQLStructType 98 }{ 99 {&bq.StandardSqlStructType{}, &StandardSQLStructType{}}, 100 { 101 &bq.StandardSqlStructType{ 102 Fields: []*bq.StandardSqlField{ 103 { 104 Name: "foo", 105 Type: &bq.StandardSqlDataType{ 106 TypeKind: "STRING", 107 }, 108 }, 109 }, 110 }, 111 &StandardSQLStructType{ 112 Fields: []*StandardSQLField{ 113 { 114 Name: "foo", 115 Type: &StandardSQLDataType{ 116 TypeKind: "STRING", 117 }, 118 }, 119 }, 120 }, 121 }, 122 } { 123 got, err := bqToStandardSQLStructType(test.in) 124 if err != nil { 125 t.Fatal(err) 126 } 127 if diff := testutil.Diff(got, test.want); diff != "" { 128 t.Errorf("%+v: -got, +want:\n%s", test.in, diff) 129 } 130 } 131} 132