| 52 | } |
| 53 | |
| 54 | func TestSpec_Validate(t *testing.T) { |
| 55 | zero, one, dur0 := int64(0), int64(1), configtype.NewDuration(0) |
| 56 | cases := []struct { |
| 57 | Give Spec |
| 58 | WantErr bool |
| 59 | }{ |
| 60 | {Give: Spec{Path: "test/path", FileSpec: filetypes.FileSpec{Format: "json"}, Bucket: "mybucket", Region: region, BatchSize: &zero, BatchSizeBytes: &zero, BatchTimeout: &dur0, ACL: "bucket-owner-full-control"}, WantErr: false}, |
| 61 | {Give: Spec{Path: "test/path", FileSpec: filetypes.FileSpec{Format: "json"}, Region: "region", BatchSize: &zero, BatchSizeBytes: &zero, BatchTimeout: &dur0}, WantErr: true}, // no bucket |
| 62 | {Give: Spec{Path: "test/path/{{TABLE}}.{{UUID}}", FileSpec: filetypes.FileSpec{Format: "json"}, NoRotate: false, Bucket: "mybucket", Region: region, BatchSize: &zero, BatchSizeBytes: &zero, BatchTimeout: &dur0}, WantErr: false}, |
| 63 | {Give: Spec{Path: "test/path/{{TABLE}}.{{UUID}}", FileSpec: filetypes.FileSpec{Format: "parquet"}, NoRotate: false, Bucket: "mybucket", Region: region, BatchSize: &zero, BatchSizeBytes: &zero, BatchTimeout: &dur0, GenerateEmptyObjects: true}, WantErr: false}, |
| 64 | {Give: Spec{Path: "test/path/{{TABLE}}.{{UUID}}", FileSpec: filetypes.FileSpec{Format: "parquet"}, NoRotate: false, Bucket: "mybucket", Region: region, BatchSize: &zero, BatchSizeBytes: &zero, BatchTimeout: &dur0, GenerateEmptyObjects: false}, WantErr: false}, |
| 65 | {Give: Spec{Path: "test/path/{{TABLE}}.{{UUID}}", FileSpec: filetypes.FileSpec{Format: "json"}, NoRotate: false, Bucket: "mybucket", Region: region, BatchSize: &zero, BatchSizeBytes: &zero, BatchTimeout: &dur0, GenerateEmptyObjects: true}, WantErr: true}, // when empty_objects is enabled, format must be parquet |
| 66 | {Give: Spec{Path: "test/path/{{TABLE}}.{{UUID}}", FileSpec: filetypes.FileSpec{Format: "json"}, NoRotate: true, Bucket: "mybucket", Region: region, BatchSize: &zero, BatchSizeBytes: &zero, BatchTimeout: &dur0}, WantErr: true}, // can't have no_rotate and {{UUID}} |
| 67 | {Give: Spec{Path: "test/path/{{TABLE}}", FileSpec: filetypes.FileSpec{Format: "json"}, NoRotate: false, Bucket: "mybucket", Region: region, BatchSize: &one, BatchSizeBytes: &zero, BatchTimeout: &dur0}, WantErr: true}, // can't have nonzero batch size and no {{UUID}} |
| 68 | {Give: Spec{Path: "/test/path/{{TABLE}}.{{UUID}}", FileSpec: filetypes.FileSpec{Format: "json"}, NoRotate: true, Bucket: "mybucket", Region: region, BatchSize: &zero, BatchSizeBytes: &zero, BatchTimeout: &dur0}, WantErr: true}, // begins with a slash |
| 69 | {Give: Spec{Path: "//test/path/{{TABLE}}.{{UUID}}", FileSpec: filetypes.FileSpec{Format: "json"}, NoRotate: true, Bucket: "mybucket", Region: region, BatchSize: &zero, BatchSizeBytes: &zero, BatchTimeout: &dur0}, WantErr: true}, // duplicate slashes |
| 70 | {Give: Spec{Path: "test//path", FileSpec: filetypes.FileSpec{Format: "json"}, Bucket: "mybucket", Region: region, BatchSize: &zero, BatchSizeBytes: &zero, BatchTimeout: &dur0}, WantErr: true}, // duplicate slashes |
| 71 | {Give: Spec{Path: "test/path/{{TABLE}}.{{UUID}}", FileSpec: filetypes.FileSpec{Format: "json"}, Bucket: "mybucket", Region: region, BatchSize: &zero, BatchSizeBytes: &zero, BatchTimeout: &dur0, ACL: "invalid"}, WantErr: true}, |
| 72 | {Give: Spec{Path: "test/path/{{TABLE}}.{{UUID}}", FileSpec: filetypes.FileSpec{Format: "json"}, Bucket: "mybucket", Region: region, LocalProfile: "my_aws_profile"}, WantErr: false}, // local profile is valid |
| 73 | {Give: Spec{Path: "test/path/{{TABLE}}.{{UUID}}", FileSpec: filetypes.FileSpec{Format: "json"}, Bucket: "mybucket", Region: region, LocalProfile: "my_aws_profile", Credentials: &Credentials{LocalProfile: "my_aws_profile"}}, WantErr: true}, // can't use both local_profile and credentials |
| 74 | {Give: Spec{Path: "test/path/{{TABLE}}.{{UUID}}", FileSpec: filetypes.FileSpec{Format: "json"}, Bucket: "mybucket", Region: region, LocalProfile: "my_aws_profile", Credentials: &Credentials{RoleSessionName: "my_aws_profile"}}, WantErr: true}, // can't use both local_profile and credentials |
| 75 | {Give: Spec{Path: "test/path/{{TABLE}}.{{UUID}}", FileSpec: filetypes.FileSpec{Format: "json"}, Bucket: "mybucket", Region: region, Credentials: &Credentials{LocalProfile: "my_aws_profile"}}, WantErr: false}, |
| 76 | } |
| 77 | for i, tc := range cases { |
| 78 | tc := tc |
| 79 | t.Run(fmt.Sprintf("Case %d", i+1), func(t *testing.T) { |
| 80 | err := tc.Give.Validate() |
| 81 | if tc.WantErr { |
| 82 | require.Error(t, err) |
| 83 | } else { |
| 84 | require.NoError(t, err) |
| 85 | } |
| 86 | }) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | func boolPtr(b bool) *bool { |
| 91 | return &b |