Skip to content

Commit f80895b

Browse files
committed
fixes for make reviewable
1 parent f3d5dee commit f80895b

4 files changed

Lines changed: 108 additions & 108 deletions

File tree

config/cluster/compute/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ func Configure(p *config.Provider) { //nolint: gocyclo
523523
// initial observe call fails instead of recognizing the resource
524524
// needs to be created.
525525
// See: https://github.com/crossplane-contrib/provider-upjet-gcp/issues/836
526-
origRead := r.TerraformResource.Read
527-
r.TerraformResource.Read = func(d *schema.ResourceData, meta interface{}) error {
526+
origRead := r.TerraformResource.Read //nolint:staticcheck // upstream resource uses deprecated Read field
527+
r.TerraformResource.Read = func(d *schema.ResourceData, meta interface{}) error { //nolint:staticcheck // wrapping upstream's deprecated Read field
528528
err := origRead(d, meta)
529529
if err != nil && strings.Contains(err.Error(), "does not contain a rule at priority") {
530530
d.SetId("")
Lines changed: 103 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,103 @@
1-
// SPDX-FileCopyrightText: 2024 The Crossplane Authors <https://crossplane.io>
2-
//
3-
// SPDX-License-Identifier: CC0-1.0
4-
5-
package compute
6-
7-
import (
8-
"errors"
9-
"strings"
10-
"testing"
11-
12-
"github.com/google/go-cmp/cmp"
13-
"github.com/google/go-cmp/cmp/cmpopts"
14-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
15-
)
16-
17-
func TestNetworkFirewallPolicyRuleReadWrapper(t *testing.T) {
18-
type args struct {
19-
origErr error
20-
id string
21-
}
22-
type want struct {
23-
err error
24-
id string
25-
}
26-
cases := map[string]struct {
27-
reason string
28-
args args
29-
want want
30-
}{
31-
"NotFoundError": {
32-
reason: "A 400 error indicating the rule does not exist should clear the ID and return nil",
33-
args: args{
34-
origErr: errors.New(`Error when reading or editing ComputeNetworkFirewallPolicyRule "projects/my-project/global/firewallPolicies/my-policy/rules/328": googleapi: Error 400: Invalid value for field 'priority': '328'. The firewall policy does not contain a rule at priority 328., invalid`),
35-
id: "projects/my-project/global/firewallPolicies/my-policy/rules/328",
36-
},
37-
want: want{
38-
err: nil,
39-
id: "",
40-
},
41-
},
42-
"OtherError": {
43-
reason: "Other errors should be returned as-is without clearing the ID",
44-
args: args{
45-
origErr: errors.New("some other API error"),
46-
id: "projects/my-project/global/firewallPolicies/my-policy/rules/328",
47-
},
48-
want: want{
49-
err: cmpopts.AnyError,
50-
id: "projects/my-project/global/firewallPolicies/my-policy/rules/328",
51-
},
52-
},
53-
"NoError": {
54-
reason: "A successful read should pass through without modification",
55-
args: args{
56-
origErr: nil,
57-
id: "projects/my-project/global/firewallPolicies/my-policy/rules/328",
58-
},
59-
want: want{
60-
err: nil,
61-
id: "projects/my-project/global/firewallPolicies/my-policy/rules/328",
62-
},
63-
},
64-
}
65-
66-
for name, tc := range cases {
67-
t.Run(name, func(t *testing.T) {
68-
// Create a minimal schema.Resource to get a valid ResourceData.
69-
r := &schema.Resource{
70-
Schema: map[string]*schema.Schema{
71-
"priority": {
72-
Type: schema.TypeInt,
73-
Optional: true,
74-
},
75-
},
76-
}
77-
d := r.TestResourceData()
78-
d.SetId(tc.args.id)
79-
80-
// Build the wrapper the same way the configurator does.
81-
origRead := func(d *schema.ResourceData, meta interface{}) error {
82-
return tc.args.origErr
83-
}
84-
wrappedRead := func(d *schema.ResourceData, meta interface{}) error {
85-
err := origRead(d, meta)
86-
if err != nil && strings.Contains(err.Error(), "does not contain a rule at priority") {
87-
d.SetId("")
88-
return nil
89-
}
90-
return err
91-
}
92-
93-
err := wrappedRead(d, nil)
94-
95-
if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" {
96-
t.Errorf("%s\nwrappedRead(...): -want error, +got error:\n%s", tc.reason, diff)
97-
}
98-
if diff := cmp.Diff(tc.want.id, d.Id()); diff != "" {
99-
t.Errorf("%s\nwrappedRead(...): -want ID, +got ID:\n%s", tc.reason, diff)
100-
}
101-
})
102-
}
103-
}
1+
// SPDX-FileCopyrightText: 2024 The Crossplane Authors <https://crossplane.io>
2+
//
3+
// SPDX-License-Identifier: CC0-1.0
4+
5+
package compute
6+
7+
import (
8+
"errors"
9+
"strings"
10+
"testing"
11+
12+
"github.com/google/go-cmp/cmp"
13+
"github.com/google/go-cmp/cmp/cmpopts"
14+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
15+
)
16+
17+
func TestNetworkFirewallPolicyRuleReadWrapper(t *testing.T) {
18+
type args struct {
19+
origErr error
20+
id string
21+
}
22+
type want struct {
23+
err error
24+
id string
25+
}
26+
cases := map[string]struct {
27+
reason string
28+
args args
29+
want want
30+
}{
31+
"NotFoundError": {
32+
reason: "A 400 error indicating the rule does not exist should clear the ID and return nil",
33+
args: args{
34+
origErr: errors.New(`Error when reading or editing ComputeNetworkFirewallPolicyRule "projects/my-project/global/firewallPolicies/my-policy/rules/328": googleapi: Error 400: Invalid value for field 'priority': '328'. The firewall policy does not contain a rule at priority 328., invalid`),
35+
id: "projects/my-project/global/firewallPolicies/my-policy/rules/328",
36+
},
37+
want: want{
38+
err: nil,
39+
id: "",
40+
},
41+
},
42+
"OtherError": {
43+
reason: "Other errors should be returned as-is without clearing the ID",
44+
args: args{
45+
origErr: errors.New("some other API error"),
46+
id: "projects/my-project/global/firewallPolicies/my-policy/rules/328",
47+
},
48+
want: want{
49+
err: cmpopts.AnyError,
50+
id: "projects/my-project/global/firewallPolicies/my-policy/rules/328",
51+
},
52+
},
53+
"NoError": {
54+
reason: "A successful read should pass through without modification",
55+
args: args{
56+
origErr: nil,
57+
id: "projects/my-project/global/firewallPolicies/my-policy/rules/328",
58+
},
59+
want: want{
60+
err: nil,
61+
id: "projects/my-project/global/firewallPolicies/my-policy/rules/328",
62+
},
63+
},
64+
}
65+
66+
for name, tc := range cases {
67+
t.Run(name, func(t *testing.T) {
68+
// Create a minimal schema.Resource to get a valid ResourceData.
69+
r := &schema.Resource{
70+
Schema: map[string]*schema.Schema{
71+
"priority": {
72+
Type: schema.TypeInt,
73+
Optional: true,
74+
},
75+
},
76+
}
77+
d := r.TestResourceData()
78+
d.SetId(tc.args.id)
79+
80+
// Build the wrapper the same way the configurator does.
81+
origRead := func(d *schema.ResourceData, meta interface{}) error {
82+
return tc.args.origErr
83+
}
84+
wrappedRead := func(d *schema.ResourceData, meta interface{}) error {
85+
err := origRead(d, meta)
86+
if err != nil && strings.Contains(err.Error(), "does not contain a rule at priority") {
87+
d.SetId("")
88+
return nil
89+
}
90+
return err
91+
}
92+
93+
err := wrappedRead(d, nil)
94+
95+
if diff := cmp.Diff(tc.want.err, err, cmpopts.EquateErrors()); diff != "" {
96+
t.Errorf("%s\nwrappedRead(...): -want error, +got error:\n%s", tc.reason, diff)
97+
}
98+
if diff := cmp.Diff(tc.want.id, d.Id()); diff != "" {
99+
t.Errorf("%s\nwrappedRead(...): -want ID, +got ID:\n%s", tc.reason, diff)
100+
}
101+
})
102+
}
103+
}

config/namespaced/compute/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,8 @@ func Configure(p *config.Provider) { //nolint: gocyclo
523523
// initial observe call fails instead of recognizing the resource
524524
// needs to be created.
525525
// See: https://github.com/crossplane-contrib/provider-upjet-gcp/issues/836
526-
origRead := r.TerraformResource.Read
527-
r.TerraformResource.Read = func(d *schema.ResourceData, meta interface{}) error {
526+
origRead := r.TerraformResource.Read //nolint:staticcheck // upstream resource uses deprecated Read field
527+
r.TerraformResource.Read = func(d *schema.ResourceData, meta interface{}) error { //nolint:staticcheck // wrapping upstream's deprecated Read field
528528
err := origRead(d, meta)
529529
if err != nil && strings.Contains(err.Error(), "does not contain a rule at priority") {
530530
d.SetId("")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/crossplane/crossplane-runtime/v2 v2.0.0-20250730220209-c306b1c8b181
1515
github.com/crossplane/crossplane-tools v0.0.0-20250731192036-00d407d8b7ec
1616
github.com/crossplane/upjet/v2 v2.0.1-0.20251028081228-8d73164bb9bd
17+
github.com/google/go-cmp v0.7.0
1718
github.com/hashicorp/terraform-json v0.25.0
1819
github.com/hashicorp/terraform-plugin-sdk/v2 v2.37.0
1920
github.com/hashicorp/terraform-provider-google v1.20.1-0.20250805162037-2fd0afa09363
@@ -78,7 +79,6 @@ require (
7879
github.com/golang/mock v1.6.0 // indirect
7980
github.com/golang/protobuf v1.5.4 // indirect
8081
github.com/google/gnostic-models v0.6.9 // indirect
81-
github.com/google/go-cmp v0.7.0 // indirect
8282
github.com/google/go-cpy v0.0.0-20211218193943-a9c933c06932 // indirect
8383
github.com/google/s2a-go v0.1.9 // indirect
8484
github.com/google/uuid v1.6.0 // indirect

0 commit comments

Comments
 (0)