You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

99 lines
2.5 KiB

  1. // Copyright 2016 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. package bigquery
  15. import (
  16. "testing"
  17. "cloud.google.com/go/internal/pretty"
  18. "cloud.google.com/go/internal/testutil"
  19. bq "google.golang.org/api/bigquery/v2"
  20. )
  21. var (
  22. hyphen = "-"
  23. fc = FileConfig{
  24. SourceFormat: CSV,
  25. AutoDetect: true,
  26. MaxBadRecords: 7,
  27. IgnoreUnknownValues: true,
  28. Schema: Schema{
  29. stringFieldSchema(),
  30. nestedFieldSchema(),
  31. },
  32. CSVOptions: CSVOptions{
  33. Quote: hyphen,
  34. FieldDelimiter: "\t",
  35. SkipLeadingRows: 8,
  36. AllowJaggedRows: true,
  37. AllowQuotedNewlines: true,
  38. Encoding: UTF_8,
  39. },
  40. }
  41. )
  42. func TestFileConfigPopulateLoadConfig(t *testing.T) {
  43. want := &bq.JobConfigurationLoad{
  44. SourceFormat: "CSV",
  45. FieldDelimiter: "\t",
  46. SkipLeadingRows: 8,
  47. AllowJaggedRows: true,
  48. AllowQuotedNewlines: true,
  49. Autodetect: true,
  50. Encoding: "UTF-8",
  51. MaxBadRecords: 7,
  52. IgnoreUnknownValues: true,
  53. Schema: &bq.TableSchema{
  54. Fields: []*bq.TableFieldSchema{
  55. bqStringFieldSchema(),
  56. bqNestedFieldSchema(),
  57. }},
  58. Quote: &hyphen,
  59. }
  60. got := &bq.JobConfigurationLoad{}
  61. fc.populateLoadConfig(got)
  62. if !testutil.Equal(got, want) {
  63. t.Errorf("got:\n%v\nwant:\n%v", pretty.Value(got), pretty.Value(want))
  64. }
  65. }
  66. func TestFileConfigPopulateExternalDataConfig(t *testing.T) {
  67. got := &bq.ExternalDataConfiguration{}
  68. fc.populateExternalDataConfig(got)
  69. want := &bq.ExternalDataConfiguration{
  70. SourceFormat: "CSV",
  71. Autodetect: true,
  72. MaxBadRecords: 7,
  73. IgnoreUnknownValues: true,
  74. Schema: &bq.TableSchema{
  75. Fields: []*bq.TableFieldSchema{
  76. bqStringFieldSchema(),
  77. bqNestedFieldSchema(),
  78. }},
  79. CsvOptions: &bq.CsvOptions{
  80. AllowJaggedRows: true,
  81. AllowQuotedNewlines: true,
  82. Encoding: "UTF-8",
  83. FieldDelimiter: "\t",
  84. Quote: &hyphen,
  85. SkipLeadingRows: 8,
  86. },
  87. }
  88. if diff := testutil.Diff(got, want); diff != "" {
  89. t.Errorf("got=-, want=+:\n%s", diff)
  90. }
  91. }