Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
fix: IgnoreErrors were showing as warn and errors (#211)
Browse files Browse the repository at this point in the history
* fix: IgnoreErrors were showing as warn and errors

* fix: Fix tests
  • Loading branch information
yevgenypats authored Mar 20, 2022
1 parent 6d3733c commit c388459
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*/.cq/*
.cq/
config.hcl

.vscode
5 changes: 3 additions & 2 deletions provider/execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,10 @@ func (e TableExecutor) callTableResolve(ctx context.Context, client schema.Clien
if err := e.Table.Resolver(ctx, client, parent, res); err != nil {
if e.Table.IgnoreError != nil && e.Table.IgnoreError(err) {
client.Logger().Warn("ignored an error", "err", err, "table", e.Table.Name)
err = diag.NewBaseError(err, diag.RESOLVING, diag.WithSeverity(diag.IGNORE), diag.WithSummary("table %q resolver ignored error", e.Table.Name))
} else {
resolverErr = e.handleResolveError(client, parent, err)
}
resolverErr = e.handleResolveError(client, parent, err)

}
}()

Expand Down
11 changes: 1 addition & 10 deletions provider/execution/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,7 @@ func TestTableExecutor_Resolve(t *testing.T) {
Resolver: returnErrorResolver,
Columns: commonColumns,
},
ErrorExpected: true,
ExpectedDiags: []diag.FlatDiag{
{
Err: "some error",
Resource: "error_returning_ignore",
Severity: diag.IGNORE,
Summary: `table "simple" resolver ignored error: some error`,
Type: diag.RESOLVING,
},
},
ErrorExpected: false,
},
{
Name: "always_delete",
Expand Down
6 changes: 2 additions & 4 deletions provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ type FetchResourceTableTest struct {
ExpectedFetchResponses []*cqproto.FetchResourcesResponse
ExpectedError error
MockStorageFunc func(ctrl *gomock.Controller) *mock.MockStorage
PartialFetch bool
ResourcesToFetch []string
Context func() context.Context
}
Expand Down Expand Up @@ -326,17 +325,17 @@ func TestProvider_FetchResources(t *testing.T) {
Summary: cqproto.ResourceFetchSummary{
Status: cqproto.ResourceFetchComplete,
ResourceCount: 0,
Diagnostics: diag.Diagnostics{diag.NewBaseError(errors.New("bad error"), diag.RESOLVING, diag.WithResourceName("bad_resource_ignore_error"), diag.WithSeverity(diag.IGNORE), diag.WithSummary(`table "bad_resource_ignore_error" resolver ignored error`))},
Diagnostics: diag.Diagnostics{},
},
}},
ExpectedError: nil,
MockStorageFunc: func(ctrl *gomock.Controller) *mock.MockStorage {
mockDB := mock.NewMockStorage(ctrl)
mockDB.EXPECT().Dialect().Return(schema.PostgresDialect{})
mockDB.EXPECT().RemoveStaleData(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil)
mockDB.EXPECT().Close()
return mockDB
},
PartialFetch: true,
ResourcesToFetch: []string{"bad_resource_ignore_error"},
},
{
Expand All @@ -357,7 +356,6 @@ func TestProvider_FetchResources(t *testing.T) {
mockDB.EXPECT().Close()
return mockDB
},
PartialFetch: false,
ResourcesToFetch: []string{"bad_resource"},
},
{
Expand Down

0 comments on commit c388459

Please sign in to comment.