Skip to content

Commit c843799

Browse files
committed
test(gcp/computeengine): fix godot, misspell, fieldalignment in client_test.go
Add period to mock type doc comments (godot); fix British-spelling misspellings in test comments (behaviour->behavior, cancelled->canceled, unrecognised->unrecognized); reorder mock struct fields for optimal alignment (govet/fieldalignment); remove unused index field from MockCommitmentsService. String literal in assert.Contains that matches the production error spelling is nolint-suppressed.
1 parent ea7a666 commit c843799

1 file changed

Lines changed: 24 additions & 25 deletions

File tree

‎providers/gcp/services/computeengine/client_test.go‎

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ import (
1919
"github.com/LeanerCloud/CUDly/pkg/scorer"
2020
)
2121

22-
// MockCommitmentsService mocks the CommitmentsService interface
22+
// MockCommitmentsService mocks the CommitmentsService interface.
2323
type MockCommitmentsService struct {
24-
commitments []*computepb.Commitment
25-
operation *MockOperation
2624
listErr error
2725
insertErr error
28-
index int
29-
lastInsertReq *computepb.InsertRegionCommitmentRequest // captured for assertions
26+
lastInsertReq *computepb.InsertRegionCommitmentRequest // captured for assertions
27+
operation *MockOperation
3028
insertReqs []*computepb.InsertRegionCommitmentRequest // every Insert call (re-drive assertions)
29+
commitments []*computepb.Commitment
3130
}
3231

3332
func (m *MockCommitmentsService) List(ctx context.Context, req *computepb.ListRegionCommitmentsRequest) CommitmentsIterator {
@@ -47,11 +46,11 @@ func (m *MockCommitmentsService) Close() error {
4746
return nil
4847
}
4948

50-
// MockCommitmentsIterator mocks the CommitmentsIterator interface
49+
// MockCommitmentsIterator mocks the CommitmentsIterator interface.
5150
type MockCommitmentsIterator struct {
51+
err error
5252
commitments []*computepb.Commitment
5353
index int
54-
err error
5554
}
5655

5756
func (m *MockCommitmentsIterator) Next() (*computepb.Commitment, error) {
@@ -66,7 +65,7 @@ func (m *MockCommitmentsIterator) Next() (*computepb.Commitment, error) {
6665
return c, nil
6766
}
6867

69-
// MockOperation mocks the CommitmentsOperation interface
68+
// MockOperation mocks the CommitmentsOperation interface.
7069
type MockOperation struct {
7170
err error
7271
}
@@ -75,10 +74,10 @@ func (m *MockOperation) Wait(ctx context.Context, opts ...gax.CallOption) error
7574
return m.err
7675
}
7776

78-
// MockMachineTypesService mocks the MachineTypesService interface
77+
// MockMachineTypesService mocks the MachineTypesService interface.
7978
type MockMachineTypesService struct {
80-
machineTypes []*computepb.MachineType
8179
err error
80+
machineTypes []*computepb.MachineType
8281
}
8382

8483
func (m *MockMachineTypesService) List(ctx context.Context, req *computepb.ListMachineTypesRequest) MachineTypesIterator {
@@ -89,11 +88,11 @@ func (m *MockMachineTypesService) Close() error {
8988
return nil
9089
}
9190

92-
// MockMachineTypesIterator mocks the MachineTypesIterator interface
91+
// MockMachineTypesIterator mocks the MachineTypesIterator interface.
9392
type MockMachineTypesIterator struct {
93+
err error
9494
machineTypes []*computepb.MachineType
9595
index int
96-
err error
9796
}
9897

9998
func (m *MockMachineTypesIterator) Next() (*computepb.MachineType, error) {
@@ -108,7 +107,7 @@ func (m *MockMachineTypesIterator) Next() (*computepb.MachineType, error) {
108107
return mt, nil
109108
}
110109

111-
// MockBillingService mocks the BillingService interface
110+
// MockBillingService mocks the BillingService interface.
112111
type MockBillingService struct {
113112
skus *cloudbilling.ListSkusResponse
114113
err error
@@ -121,11 +120,11 @@ func (m *MockBillingService) ListSKUs(serviceID string) (*cloudbilling.ListSkusR
121120
return m.skus, nil
122121
}
123122

124-
// MockRecommenderIterator mocks the RecommenderIterator interface
123+
// MockRecommenderIterator mocks the RecommenderIterator interface.
125124
type MockRecommenderIterator struct {
125+
err error
126126
recommendations []*recommenderpb.Recommendation
127127
index int
128-
err error
129128
}
130129

131130
func (m *MockRecommenderIterator) Next() (*recommenderpb.Recommendation, error) {
@@ -140,7 +139,7 @@ func (m *MockRecommenderIterator) Next() (*recommenderpb.Recommendation, error)
140139
return rec, nil
141140
}
142141

143-
// MockRecommenderClient mocks the RecommenderClient interface
142+
// MockRecommenderClient mocks the RecommenderClient interface.
144143
type MockRecommenderClient struct {
145144
iterator RecommenderIterator
146145
closed bool
@@ -577,7 +576,7 @@ func TestComputeEngineClient_PurchaseCommitment_IdempotentReDrive(t *testing.T)
577576

578577
// TestComputeEngineClient_PurchaseCommitment_EmptyTokenNoRequestID confirms the
579578
// CLI path (no owning execution, empty token) keeps its prior non-idempotent
580-
// behaviour: no RequestId is set and the name is the timestamp-based fallback.
579+
// behavior: no RequestId is set and the name is the timestamp-based fallback.
581580
func TestComputeEngineClient_PurchaseCommitment_EmptyTokenNoRequestID(t *testing.T) {
582581
ctx := context.Background()
583582
client, _ := NewClient(ctx, "test-project", "us-central1")
@@ -921,7 +920,7 @@ func (c *infiniteRecommenderClient) ListRecommendations(_ context.Context, _ *re
921920
func (c *infiniteRecommenderClient) Close() error { return nil }
922921

923922
// TestComputeEngineClient_GetRecommendations_CtxCancelReturnsError asserts
924-
// that a cancelled context is treated as a terminal stop and returns an error
923+
// that a canceled context is treated as a terminal stop and returns an error
925924
// rather than silently producing a partial result set
926925
// (feedback_ctx_cancel_terminal).
927926
func TestComputeEngineClient_GetRecommendations_CtxCancelReturnsError(t *testing.T) {
@@ -933,7 +932,7 @@ func TestComputeEngineClient_GetRecommendations_CtxCancelReturnsError(t *testing
933932
client.SetRecommenderClient(&infiniteRecommenderClient{})
934933

935934
_, err = client.GetRecommendations(ctx, common.RecommendationParams{})
936-
require.Error(t, err, "cancelled context must surface an error, not a partial result set")
935+
require.Error(t, err, "canceled context must surface an error, not a partial result set")
937936
}
938937

939938
// TestComputeEngineClient_GetRecommendations_PageCapFires asserts that the
@@ -1427,16 +1426,16 @@ func TestTermPlan_UsesSdkEnumConstants(t *testing.T) {
14271426

14281427
// TestTermPlan_RejectsUnknownTerm is the regression test for the "fail loud" policy:
14291428
// termPlan must return an error rather than silently defaulting to 12 months when
1430-
// given an unrecognised or empty term. A silent mis-default can purchase the wrong
1429+
// given an unrecognized or empty term. A silent mis-default can purchase the wrong
14311430
// duration and waste money.
14321431
//
14331432
// This test fails on pre-fix code that silently returned TWELVE_MONTH for any
1434-
// unrecognised input.
1433+
// unrecognized input.
14351434
func TestTermPlan_RejectsUnknownTerm(t *testing.T) {
14361435
for _, badTerm := range []string{"", "2yr", "invalid", "24mo", "forever"} {
14371436
_, err := termPlan(badTerm)
1438-
require.Error(t, err, "termPlan must reject unrecognised term %q (no silent 12-month default)", badTerm)
1439-
assert.Contains(t, err.Error(), "unrecognised commitment term",
1437+
require.Error(t, err, "termPlan must reject unrecognized term %q (no silent 12-month default)", badTerm)
1438+
assert.Contains(t, err.Error(), "unrecognised commitment term", //nolint:misspell // matches production error string
14401439
"error for term %q must identify the bad input", badTerm)
14411440
}
14421441
}
@@ -1489,7 +1488,7 @@ func TestConvertGCPRecommendation_PropagatesParamsTerm(t *testing.T) {
14891488
}
14901489

14911490
// TestConvertGCPRecommendation_RejectsUnknownTerm asserts that convertGCPRecommendation
1492-
// returns nil when given an unrecognised params.Term (e.g. "5yr"). An unroutable
1491+
// returns nil when given an unrecognized params.Term (e.g. "5yr"). An unroutable
14931492
// recommendation must be dropped before it can reach buildInsertRequest and attempt
14941493
// to insert a commitment with an invalid plan.
14951494
//
@@ -1502,7 +1501,7 @@ func TestConvertGCPRecommendation_RejectsUnknownTerm(t *testing.T) {
15021501

15031502
rec := client.convertGCPRecommendation(ctx, gcpRec, common.RecommendationParams{Term: "5yr"})
15041503
assert.Nil(t, rec,
1505-
"convertGCPRecommendation must return nil for unrecognised term (not silently default to 12 months)")
1504+
"convertGCPRecommendation must return nil for unrecognized term (not silently default to 12 months)")
15061505
}
15071506

15081507
// TestGetRecommendations_FiltersNonActiveStates is a regression test for H-1

0 commit comments

Comments
 (0)