Skip to content

Commit 3da6e28

Browse files
committed
Fixed lintier
1 parent 9e1d041 commit 3da6e28

File tree

8 files changed

+18
-16
lines changed

8 files changed

+18
-16
lines changed

helper/resource/query/query_checks.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func RunQueryChecks(ctx context.Context, t testing.T, query *[]tfjson.LogMsg, qu
2020
var result []error
2121

2222
if query == nil || len(*query) == 0 {
23-
// TODO return error
23+
result = append(result, fmt.Errorf("No query results found"))
2424
}
2525

2626
found := make([]tfjson.ListResourceFoundData, 0)
@@ -33,6 +33,8 @@ func RunQueryChecks(ctx context.Context, t testing.T, query *[]tfjson.LogMsg, qu
3333
case tfjson.ListCompleteMessage:
3434
complete = v.ListComplete
3535
// TODO diagnostics and errors?
36+
default:
37+
// ignore other message types
3638
}
3739
}
3840

internal/plugintest/working_dir.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ func (wd *WorkingDir) Query(ctx context.Context) ([]tfjson.LogMsg, error) {
544544

545545
message, related, err = logEmit.NextMessage()
546546

547-
if related == false && err != nil {
547+
if !related && err != nil {
548548
return nil, fmt.Errorf("Error no messages found from terraform query command: %w", err)
549549
}
550550

@@ -557,7 +557,7 @@ func (wd *WorkingDir) Query(ctx context.Context) ([]tfjson.LogMsg, error) {
557557
}
558558
}
559559

560-
if related == true {
560+
if related {
561561
return nil, fmt.Errorf("Error running terraform query command: %w", err)
562562
}
563563

internal/testing/testsdk/providerserver/providerserver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ func (s ProviderServer) ListResource(ctx context.Context, req *tfprotov6.ListRes
10531053
return nil, fmt.Errorf("failed to retrieve resource: %v", err)
10541054
}
10551055
r.IdentitySchema(ctx, identitySchemaReq, identitySchemaResp)
1056-
if identitySchemaResp.Diagnostics != nil && len(identitySchemaResp.Diagnostics) > 0 {
1056+
if len(identitySchemaResp.Diagnostics) > 0 {
10571057
return nil, fmt.Errorf("failed to retrieve resource schema: %v", identitySchemaResp.Diagnostics)
10581058
}
10591059

@@ -1066,7 +1066,7 @@ func (s ProviderServer) ListResource(ctx context.Context, req *tfprotov6.ListRes
10661066
schemaResp := &list.SchemaResponse{}
10671067

10681068
listresource.Schema(ctx, schemaReq, schemaResp)
1069-
if schemaResp.Diagnostics != nil && len(schemaResp.Diagnostics) > 0 {
1069+
if len(schemaResp.Diagnostics) > 0 {
10701070
return nil, fmt.Errorf("failed to retrieve resource schema: %v", schemaResp.Diagnostics)
10711071
}
10721072

querycheck/contains.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ func (c contains) CheckQuery(_ context.Context, req CheckQueryRequest, resp *Che
2121
if strings.EqualFold(c.check, res.DisplayName) {
2222
return
2323
}
24-
2524
}
2625

2726
resp.Error = fmt.Errorf("expected to find resource with display name %q in results but resource was not found", c.check)
2827

29-
return
3028
}
3129

3230
// Contains returns a query check that asserts that a resource with a given display name exists within the returned results of the query.

querycheck/expect_identity.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ func (e expectIdentity) CheckQuery(ctx context.Context, req CheckQueryRequest, r
6666
errCollection = append(errCollection, fmt.Errorf("Address: %s\n", e.resourceAddress))
6767

6868
resp.Error = errors.Join(errCollection...)
69-
70-
return
7169
}
7270

7371
// ExpectIdentity returns a query check that asserts that the identity at the given resource matches a known object, where each

querycheck/expect_known_value.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"context"
88
"encoding/json"
99
"fmt"
10+
"strings"
11+
1012
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
1113
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
12-
"strings"
1314
)
1415

1516
var _ QueryResultCheck = expectKnownValue{}
@@ -63,11 +64,18 @@ func (e expectKnownValue) CheckQuery(_ context.Context, req CheckQueryRequest, r
6364
}
6465
}
6566
}
67+
68+
if diags != nil {
69+
var diagsStr string
70+
for _, diag := range diags {
71+
diagsStr += diag.Error() + "; "
72+
}
73+
resp.Error = fmt.Errorf(diagsStr)
74+
return
75+
}
6676
}
6777

6878
resp.Error = fmt.Errorf("%s - the resource %s was not found", e.listResourceAddress, e.resourceName)
69-
70-
return
7179
}
7280

7381
func ExpectKnownValue(listResourceAddress string, resourceName string, attributePath tfjsonpath.Path, knownValue knownvalue.Check) QueryResultCheck {

querycheck/expect_result_length_atleast.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ func (e expectLengthAtLeast) CheckQuery(_ context.Context, req CheckQueryRequest
2626
resp.Error = fmt.Errorf("Query result of at least length %v - expected but got %v.", e.check, req.CompletedQuery.Total)
2727
return
2828
}
29-
30-
return
3129
}
3230

3331
// ExpectLengthAtLeast returns a query check that asserts that the length of the query result is at least the given value.

querycheck/expect_result_length_exact.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ func (e expectLength) CheckQuery(_ context.Context, req CheckQueryRequest, resp
3232
resp.Error = fmt.Errorf("Query result of length %v - expected but got %v.", e.check, req.CompletedQuery.Total)
3333
return
3434
}
35-
36-
return
3735
}
3836

3937
// ExpectLength returns a query check that asserts that the length of the query result is exactly the given value.

0 commit comments

Comments
 (0)