...

Source file src/cloud.google.com/go/bigquery/standardsql_test.go

Documentation: cloud.google.com/go/bigquery

     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  
    15  package bigquery
    16  
    17  import (
    18  	"testing"
    19  
    20  	"cloud.google.com/go/internal/testutil"
    21  	bq "google.golang.org/api/bigquery/v2"
    22  )
    23  
    24  func 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  			&bq.StandardSqlDataType{
    54  				TypeKind: "RANGE",
    55  				RangeElementType: &bq.StandardSqlDataType{
    56  					TypeKind: "DATETIME",
    57  				},
    58  			},
    59  			&StandardSQLDataType{
    60  				TypeKind: "RANGE",
    61  				RangeElementType: &StandardSQLDataType{
    62  					TypeKind: "DATETIME",
    63  				},
    64  			},
    65  		},
    66  	} {
    67  		got, err := bqToStandardSQLDataType(test.in)
    68  		if err != nil {
    69  			t.Fatal(err)
    70  		}
    71  		if diff := testutil.Diff(got, test.want); diff != "" {
    72  			t.Errorf("%+v: -got, +want:\n%s", test.in, diff)
    73  		}
    74  	}
    75  }
    76  
    77  func TestBQToStandardSQLField(t *testing.T) {
    78  	for _, test := range []struct {
    79  		in   *bq.StandardSqlField
    80  		want *StandardSQLField
    81  	}{
    82  		{&bq.StandardSqlField{}, &StandardSQLField{}},
    83  		{
    84  			&bq.StandardSqlField{
    85  				Name: "foo",
    86  				Type: &bq.StandardSqlDataType{
    87  					TypeKind: "NUMERIC",
    88  				},
    89  			},
    90  			&StandardSQLField{
    91  				Name: "foo",
    92  				Type: &StandardSQLDataType{
    93  					TypeKind: "NUMERIC",
    94  				},
    95  			},
    96  		},
    97  	} {
    98  		got, err := bqToStandardSQLField(test.in)
    99  		if err != nil {
   100  			t.Fatal(err)
   101  		}
   102  		if diff := testutil.Diff(got, test.want); diff != "" {
   103  			t.Errorf("%+v: -got, +want:\n%s", test.in, diff)
   104  		}
   105  	}
   106  }
   107  
   108  func TestBQToStandardSQLStructType(t *testing.T) {
   109  	for _, test := range []struct {
   110  		in   *bq.StandardSqlStructType
   111  		want *StandardSQLStructType
   112  	}{
   113  		{&bq.StandardSqlStructType{}, &StandardSQLStructType{}},
   114  		{
   115  			&bq.StandardSqlStructType{
   116  				Fields: []*bq.StandardSqlField{
   117  					{
   118  						Name: "foo",
   119  						Type: &bq.StandardSqlDataType{
   120  							TypeKind: "STRING",
   121  						},
   122  					},
   123  				},
   124  			},
   125  			&StandardSQLStructType{
   126  				Fields: []*StandardSQLField{
   127  					{
   128  						Name: "foo",
   129  						Type: &StandardSQLDataType{
   130  							TypeKind: "STRING",
   131  						},
   132  					},
   133  				},
   134  			},
   135  		},
   136  	} {
   137  		got, err := bqToStandardSQLStructType(test.in)
   138  		if err != nil {
   139  			t.Fatal(err)
   140  		}
   141  		if diff := testutil.Diff(got, test.want); diff != "" {
   142  			t.Errorf("%+v: -got, +want:\n%s", test.in, diff)
   143  		}
   144  	}
   145  }
   146  

View as plain text