-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove filters field from source config
- Loading branch information
1 parent
5f1fa72
commit 07b4473
Showing
4 changed files
with
143 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
234 changes: 114 additions & 120 deletions
234
artifact_source_config/artifact_source_config_base_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,116 @@ | ||
package artifact_source_config | ||
|
||
import ( | ||
"github.com/hashicorp/hcl/v2" | ||
"github.com/turbot/pipe-fittings/filter" | ||
"github.com/turbot/pipe-fittings/utils" | ||
"testing" | ||
) | ||
|
||
func TestArtifactSourceConfigBase_Validate(t *testing.T) { | ||
type fields struct { | ||
Remain hcl.Body | ||
FileLayout *string | ||
Filters []string | ||
FilterMap map[string]*filter.SqlFilter | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Valid filters - single filter", | ||
fields: fields{ | ||
FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail"), | ||
Filters: []string{"org = 'org1'"}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Valid filters - multiple filters", | ||
fields: fields{ | ||
FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail/%{WORD:region}/%{NOTSPACE:file_name}.%{WORD:ext}"), | ||
Filters: []string{"org = 'org1'", "region = 'us-east-1'"}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Filter refer to field not in FileLayout", | ||
fields: fields{ | ||
FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail/%{NOTSPACE:file_name}.%{WORD:ext}"), | ||
Filters: []string{"org = 'org1'", "region = 'us-east-1'"}, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Invalid filter - no LHS property", | ||
fields: fields{ | ||
FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail"), | ||
Filters: []string{"= 'org1'"}, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Invalid filter - multiple LHS properties", | ||
fields: fields{ | ||
FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail"), | ||
Filters: []string{"org = 'org1' AND account = '123'"}, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Empty filters", | ||
fields: fields{ | ||
Filters: []string{}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Nil filters", | ||
fields: fields{ | ||
Filters: nil, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Invalid filter syntax", | ||
fields: fields{ | ||
FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail"), | ||
Filters: []string{"org =="}, | ||
}, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "Duplicate filters for the same field", | ||
fields: fields{ | ||
FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail"), | ||
Filters: []string{"org = 'org1'", "org != 'org2'"}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Valid filters with FileLayout", | ||
fields: fields{ | ||
FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/%{NUMBER:account_id}/CloudTrail"), | ||
Filters: []string{"org = 'org1'", "account_id = '123'"}, | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "Empty FileLayout and Filters", | ||
fields: fields{ | ||
FileLayout: nil, | ||
Filters: []string{}, | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
b := &ArtifactSourceConfigBase{ | ||
Remain: tt.fields.Remain, | ||
FileLayout: tt.fields.FileLayout, | ||
Filters: tt.fields.Filters, | ||
FilterMap: tt.fields.FilterMap, | ||
} | ||
if err := b.Validate(); (err != nil) != tt.wantErr { | ||
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} | ||
// #TODO reenable once we support filter pushdown https://github.com/turbot/tailpipe/issues/97 | ||
//func TestArtifactSourceConfigBase_Validate(t *testing.T) { | ||
// type fields struct { | ||
// Remain hcl.Body | ||
// FileLayout *string | ||
// Filters []string | ||
// FilterMap map[string]*filter.SqlFilter | ||
// } | ||
// tests := []struct { | ||
// name string | ||
// fields fields | ||
// wantErr bool | ||
// }{ | ||
// { | ||
// name: "Valid filters - single filter", | ||
// fields: fields{ | ||
// FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail"), | ||
// Filters: []string{"org = 'org1'"}, | ||
// }, | ||
// wantErr: false, | ||
// }, | ||
// { | ||
// name: "Valid filters - multiple filters", | ||
// fields: fields{ | ||
// FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail/%{WORD:region}/%{NOTSPACE:file_name}.%{WORD:ext}"), | ||
// Filters: []string{"org = 'org1'", "region = 'us-east-1'"}, | ||
// }, | ||
// wantErr: false, | ||
// }, | ||
// { | ||
// name: "Filter refer to field not in FileLayout", | ||
// fields: fields{ | ||
// FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail/%{NOTSPACE:file_name}.%{WORD:ext}"), | ||
// Filters: []string{"org = 'org1'", "region = 'us-east-1'"}, | ||
// }, | ||
// wantErr: true, | ||
// }, | ||
// { | ||
// name: "Invalid filter - no LHS property", | ||
// fields: fields{ | ||
// FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail"), | ||
// Filters: []string{"= 'org1'"}, | ||
// }, | ||
// wantErr: true, | ||
// }, | ||
// { | ||
// name: "Invalid filter - multiple LHS properties", | ||
// fields: fields{ | ||
// FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail"), | ||
// Filters: []string{"org = 'org1' AND account = '123'"}, | ||
// }, | ||
// wantErr: true, | ||
// }, | ||
// { | ||
// name: "Empty filters", | ||
// fields: fields{ | ||
// Filters: []string{}, | ||
// }, | ||
// wantErr: false, | ||
// }, | ||
// { | ||
// name: "Nil filters", | ||
// fields: fields{ | ||
// Filters: nil, | ||
// }, | ||
// wantErr: false, | ||
// }, | ||
// { | ||
// name: "Invalid filter syntax", | ||
// fields: fields{ | ||
// FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail"), | ||
// Filters: []string{"org =="}, | ||
// }, | ||
// wantErr: true, | ||
// }, | ||
// { | ||
// name: "Duplicate filters for the same field", | ||
// fields: fields{ | ||
// FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/CloudTrail"), | ||
// Filters: []string{"org = 'org1'", "org != 'org2'"}, | ||
// }, | ||
// wantErr: false, | ||
// }, | ||
// { | ||
// name: "Valid filters with FileLayout", | ||
// fields: fields{ | ||
// FileLayout: utils.ToPointer("AWSLogs/%{WORD:org}/%{NUMBER:account_id}/CloudTrail"), | ||
// Filters: []string{"org = 'org1'", "account_id = '123'"}, | ||
// }, | ||
// wantErr: false, | ||
// }, | ||
// { | ||
// name: "Empty FileLayout and Filters", | ||
// fields: fields{ | ||
// FileLayout: nil, | ||
// Filters: []string{}, | ||
// }, | ||
// wantErr: false, | ||
// }, | ||
// } | ||
// for _, tt := range tests { | ||
// t.Run(tt.name, func(t *testing.T) { | ||
// b := &ArtifactSourceConfigBase{ | ||
// Remain: tt.fields.Remain, | ||
// FileLayout: tt.fields.FileLayout, | ||
// Filters: tt.fields.Filters, | ||
// FilterMap: tt.fields.FilterMap, | ||
// } | ||
// if err := b.Validate(); (err != nil) != tt.wantErr { | ||
// t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr) | ||
// } | ||
// }) | ||
// } | ||
//} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.