MCPcopy Create free account
hub / github.com/cloudquery/cloudquery / TestSpec_Validate

Function TestSpec_Validate

plugins/destination/s3/client/spec/spec_test.go:54–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

52}
53
54func 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
90func boolPtr(b bool) *bool {
91 return &b

Callers

nothing calls this directly

Calls 3

RunMethod · 0.80
ValidateMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected