Skip to content

Commit 3e810e5

Browse files
cvclaude
andcommitted
test: Add t.Parallel() to all tests for paralleltest linter
Add t.Parallel() calls to all test functions and table-driven subtests to comply with the paralleltest linter. Tests that cannot run in parallel are marked with //nolint:paralleltest comments: - Tests using t.Setenv (incompatible with t.Parallel) - Tests modifying global colorEnabled state - Tests modifying os.Stderr - Tests calling NewRootCmd (writes to package-level ConfigFile/NoColor) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7210947 commit 3e810e5

32 files changed

+350
-23
lines changed

cmd/mcs/main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import "testing"
44

55
func TestMain(t *testing.T) {
6+
t.Parallel()
67
// Basic smoke test to ensure main package compiles
78
// We can't actually call main() as it would call os.Exit
89
// Just verify it compiles

internal/api/auth_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
func TestClient_GetEncryptionKeys(t *testing.T) {
16+
t.Parallel()
1617
// Create a test client to get the correct decryption key
1718
testClient := &Client{
1819
email: "test@example.com",
@@ -68,6 +69,7 @@ func TestClient_GetEncryptionKeys(t *testing.T) {
6869
}
6970

7071
func TestClient_GetUsherEncryptionKey(t *testing.T) {
72+
t.Parallel()
7173
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
7274
assert.Equalf(t, "/appapi/v1/"+EndpointEncryptionKey, r.URL.Path, "Expected path /appapi/v1/"+EndpointEncryptionKey+", got %s", r.URL.Path)
7375
assert.Equalf(t, "GET", r.Method, "Expected GET method, got %s", r.Method)
@@ -102,6 +104,7 @@ func TestClient_GetUsherEncryptionKey(t *testing.T) {
102104
}
103105

104106
func TestClient_Login(t *testing.T) {
107+
t.Parallel()
105108
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
106109
switch r.URL.Path {
107110
case "/appapi/v1/" + EndpointEncryptionKey:
@@ -151,6 +154,7 @@ func TestClient_Login(t *testing.T) {
151154
}
152155

153156
func TestClient_IsTokenValid(t *testing.T) {
157+
t.Parallel()
154158
tests := []struct {
155159
name string
156160
token string
@@ -179,6 +183,7 @@ func TestClient_IsTokenValid(t *testing.T) {
179183

180184
for _, tt := range tests {
181185
t.Run(tt.name, func(t *testing.T) {
186+
t.Parallel()
182187
client := &Client{
183188
accessToken: tt.token,
184189
accessTokenExpirationTs: tt.expiration,
@@ -190,6 +195,7 @@ func TestClient_IsTokenValid(t *testing.T) {
190195
}
191196

192197
func TestRegion_String(t *testing.T) {
198+
t.Parallel()
193199
tests := []struct {
194200
name string
195201
region Region
@@ -214,13 +220,15 @@ func TestRegion_String(t *testing.T) {
214220

215221
for _, tt := range tests {
216222
t.Run(tt.name, func(t *testing.T) {
223+
t.Parallel()
217224
got := tt.region.String()
218225
assert.Equal(t, tt.want, got)
219226
})
220227
}
221228
}
222229

223230
func TestParseRegion(t *testing.T) {
231+
t.Parallel()
224232
tests := []struct {
225233
name string
226234
input string
@@ -267,6 +275,7 @@ func TestParseRegion(t *testing.T) {
267275

268276
for _, tt := range tests {
269277
t.Run(tt.name, func(t *testing.T) {
278+
t.Parallel()
270279
got, err := ParseRegion(tt.input)
271280
if tt.wantErr {
272281
require.Error(t, err, "ParseRegion() error = %v, wantErr %v")
@@ -280,6 +289,7 @@ func TestParseRegion(t *testing.T) {
280289
}
281290

282291
func TestRegion_IsValid(t *testing.T) {
292+
t.Parallel()
283293
tests := []struct {
284294
name string
285295
region Region
@@ -314,6 +324,7 @@ func TestRegion_IsValid(t *testing.T) {
314324

315325
for _, tt := range tests {
316326
t.Run(tt.name, func(t *testing.T) {
327+
t.Parallel()
317328
got := tt.region.IsValid()
318329
assert.Equal(t, tt.want, got)
319330
})

internal/api/client_integration_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
// TestAPIRequest_RetryOnEncryptionError tests that encryption errors trigger retry with new keys
1616
func TestAPIRequest_RetryOnEncryptionError(t *testing.T) {
17+
t.Parallel()
1718
requestCount := 0
1819
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1920
requestCount++
@@ -84,6 +85,7 @@ func TestAPIRequest_RetryOnEncryptionError(t *testing.T) {
8485

8586
// TestAPIRequest_MaxRetries tests that max retries is enforced
8687
func TestAPIRequest_MaxRetries(t *testing.T) {
88+
t.Parallel()
8789
requestCount := 0
8890
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
8991
requestCount++
@@ -135,6 +137,7 @@ func TestAPIRequest_MaxRetries(t *testing.T) {
135137

136138
// TestAPIRequest_EngineStartLimitError tests the engine start limit error
137139
func TestAPIRequest_EngineStartLimitError(t *testing.T) {
140+
t.Parallel()
138141
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
139142
response := map[string]any{
140143
"state": "E",
@@ -163,6 +166,7 @@ func TestAPIRequest_EngineStartLimitError(t *testing.T) {
163166

164167
// TestAPIRequest_WithQueryParams tests GET request with query parameters
165168
func TestAPIRequest_WithQueryParams(t *testing.T) {
169+
t.Parallel()
166170
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
167171
// Verify params query parameter is present
168172
assert.NotEmpty(t, r.URL.Query().Get("params"), "Expected params query parameter to be present")
@@ -199,6 +203,7 @@ func TestAPIRequest_WithQueryParams(t *testing.T) {
199203

200204
// TestEncryptPayloadUsingKey_EmptyPayload tests encryption of empty payload
201205
func TestEncryptPayloadUsingKey_EmptyPayload(t *testing.T) {
206+
t.Parallel()
202207
client, err := NewClient("test@example.com", "password", RegionMNAO)
203208
require.NoError(t, err, "Failed to create client: %v")
204209

@@ -212,6 +217,7 @@ func TestEncryptPayloadUsingKey_EmptyPayload(t *testing.T) {
212217

213218
// TestEncryptPayloadUsingKey_MissingKey tests error when encryption key is missing
214219
func TestEncryptPayloadUsingKey_MissingKey(t *testing.T) {
220+
t.Parallel()
215221
client, err := NewClient("test@example.com", "password", RegionMNAO)
216222
require.NoError(t, err, "Failed to create client: %v")
217223

@@ -224,6 +230,7 @@ func TestEncryptPayloadUsingKey_MissingKey(t *testing.T) {
224230

225231
// TestDecryptPayloadUsingKey_MissingKey tests error when decryption key is missing
226232
func TestDecryptPayloadUsingKey_MissingKey(t *testing.T) {
233+
t.Parallel()
227234
client, err := NewClient("test@example.com", "password", RegionMNAO)
228235
require.NoError(t, err, "Failed to create client: %v")
229236

@@ -239,18 +246,21 @@ func TestDecryptPayloadUsingKey_MissingKey(t *testing.T) {
239246
// multiple API endpoints (usherURL + baseURL). Skip for now - the retry logic
240247
// is tested in other tests that don't require full login flow.
241248
func TestAPIRequest_TokenExpiredRetry(t *testing.T) {
249+
t.Parallel()
242250
t.Skip("Skipping complex test - requires mocking full login flow with usherURL")
243251
}
244252

245253
// TestAPIRequest_MultipleEncryptionKeyRetries tests multiple encryption key refresh attempts
246254
// This test is already covered by TestAPIRequest_RetryOnEncryptionError, so skip this more
247255
// complex version to avoid test failures due to checkVersion encryption complexity
248256
func TestAPIRequest_MultipleEncryptionKeyRetries(t *testing.T) {
257+
t.Parallel()
249258
t.Skip("Skipping - encryption key retry is already tested in TestAPIRequest_RetryOnEncryptionError")
250259
}
251260

252261
// TestAPIRequest_ContextCancellation tests that context cancellation stops the request
253262
func TestAPIRequest_ContextCancellation(t *testing.T) {
263+
t.Parallel()
254264
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
255265
// This should not be reached due to context cancellation
256266
t.Error("Request was made despite context cancellation")
@@ -276,6 +286,7 @@ func TestAPIRequest_ContextCancellation(t *testing.T) {
276286

277287
// TestAPIRequest_ComplexDataTypes tests request/response with various data types
278288
func TestAPIRequest_ComplexDataTypes(t *testing.T) {
289+
t.Parallel()
279290
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
280291
// Return response with various data types
281292
testResponse := map[string]any{
@@ -333,6 +344,7 @@ func TestAPIRequest_ComplexDataTypes(t *testing.T) {
333344

334345
// TestAPIRequest_RequestInProgressRetry tests handling of request in progress error without retry
335346
func TestAPIRequest_RequestInProgressRetry(t *testing.T) {
347+
t.Parallel()
336348
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
337349
// Always return request in progress error (should not retry this error)
338350
response := map[string]any{
@@ -363,6 +375,7 @@ func TestAPIRequest_RequestInProgressRetry(t *testing.T) {
363375

364376
// TestAPIRequestJSON_FullFlow tests the JSON request flow (returns raw bytes instead of parsed map)
365377
func TestAPIRequestJSON_FullFlow(t *testing.T) {
378+
t.Parallel()
366379
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
367380
testResponse := map[string]any{
368381
"resultCode": "200S00",

internal/api/client_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
// TestAPIRequest_Success tests successful API request with encryption
1818
func TestAPIRequest_Success(t *testing.T) {
19+
t.Parallel()
1920
// Create a mock server
2021
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2122
// Verify headers
@@ -63,6 +64,7 @@ func TestAPIRequest_Success(t *testing.T) {
6364

6465
// TestAPIRequest_EncryptionError tests handling of encryption error response
6566
func TestAPIRequest_EncryptionError(t *testing.T) {
67+
t.Parallel()
6668
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
6769
response := map[string]any{
6870
"state": "E",
@@ -91,6 +93,7 @@ func TestAPIRequest_EncryptionError(t *testing.T) {
9193

9294
// TestAPIRequest_TokenExpired tests handling of expired token error
9395
func TestAPIRequest_TokenExpired(t *testing.T) {
96+
t.Parallel()
9497
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
9598
response := map[string]any{
9699
"state": "E",
@@ -119,6 +122,7 @@ func TestAPIRequest_TokenExpired(t *testing.T) {
119122

120123
// TestAPIRequest_RequestInProgress tests handling of request in progress error
121124
func TestAPIRequest_RequestInProgress(t *testing.T) {
125+
t.Parallel()
122126
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
123127
response := map[string]any{
124128
"state": "E",
@@ -147,6 +151,7 @@ func TestAPIRequest_RequestInProgress(t *testing.T) {
147151

148152
// TestEncryptPayloadUsingKey tests payload encryption
149153
func TestEncryptPayloadUsingKey(t *testing.T) {
154+
t.Parallel()
150155
client, err := NewClient("test@example.com", "password", RegionMNAO)
151156
require.NoError(t, err, "Failed to create client: %v")
152157

@@ -171,6 +176,7 @@ func TestEncryptPayloadUsingKey(t *testing.T) {
171176

172177
// TestDecryptPayloadUsingKey tests payload decryption
173178
func TestDecryptPayloadUsingKey(t *testing.T) {
179+
t.Parallel()
174180
client, err := NewClient("test@example.com", "password", RegionMNAO)
175181
require.NoError(t, err, "Failed to create client: %v")
176182

@@ -199,6 +205,7 @@ func TestDecryptPayloadUsingKey(t *testing.T) {
199205

200206
// TestGetSignFromPayloadAndTimestamp tests signature generation
201207
func TestGetSignFromPayloadAndTimestamp(t *testing.T) {
208+
t.Parallel()
202209
client, err := NewClient("test@example.com", "password", RegionMNAO)
203210
require.NoError(t, err, "Failed to create client: %v")
204211

@@ -217,6 +224,7 @@ func TestGetSignFromPayloadAndTimestamp(t *testing.T) {
217224

218225
// TestAPIRequest_MissingKeys tests that APIRequest attempts to get keys when missing
219226
func TestAPIRequest_MissingKeys(t *testing.T) {
227+
t.Parallel()
220228
// Create a server that returns error for checkVersion (key retrieval)
221229
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
222230
response := map[string]any{
@@ -241,6 +249,7 @@ func TestAPIRequest_MissingKeys(t *testing.T) {
241249

242250
// TestAPIRequest_POST_WithBody tests POST request with body encryption
243251
func TestAPIRequest_POST_WithBody(t *testing.T) {
252+
t.Parallel()
244253
requestReceived := false
245254
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
246255
requestReceived = true
@@ -285,6 +294,7 @@ func TestAPIRequest_POST_WithBody(t *testing.T) {
285294

286295
// TestAPIRequest_GET_WithQuery tests GET request with query parameter encryption
287296
func TestAPIRequest_GET_WithQuery(t *testing.T) {
297+
t.Parallel()
288298
requestReceived := false
289299
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
290300
requestReceived = true
@@ -329,6 +339,7 @@ func TestAPIRequest_GET_WithQuery(t *testing.T) {
329339

330340
// TestCalculateBackoff tests the backoff calculation
331341
func TestCalculateBackoff(t *testing.T) {
342+
t.Parallel()
332343
tests := []struct {
333344
retryCount int
334345
expected time.Duration
@@ -344,6 +355,7 @@ func TestCalculateBackoff(t *testing.T) {
344355

345356
for _, tt := range tests {
346357
t.Run(strings.Join([]string{"retry", strings.Repeat("x", tt.retryCount)}, "_"), func(t *testing.T) {
358+
t.Parallel()
347359
result := calculateBackoff(tt.retryCount)
348360
assert.Equalf(t, tt.expected, result, "calculateBackoff(%d) = %v, want %v", tt.retryCount, result, tt.expected)
349361
})
@@ -352,6 +364,7 @@ func TestCalculateBackoff(t *testing.T) {
352364

353365
// TestSleepWithContext_Completes tests that sleep completes normally
354366
func TestSleepWithContext_Completes(t *testing.T) {
367+
t.Parallel()
355368
ctx := context.Background()
356369
start := time.Now()
357370
duration := 100 * time.Millisecond
@@ -369,6 +382,7 @@ func TestSleepWithContext_Completes(t *testing.T) {
369382

370383
// TestSleepWithContext_Cancelled tests that sleep returns early on context cancellation
371384
func TestSleepWithContext_Cancelled(t *testing.T) {
385+
t.Parallel()
372386
ctx, cancel := context.WithCancel(context.Background())
373387
start := time.Now()
374388
duration := 5 * time.Second // Long sleep
@@ -392,6 +406,7 @@ func TestSleepWithContext_Cancelled(t *testing.T) {
392406

393407
// TestSleepWithContext_ZeroDuration tests that zero duration returns immediately
394408
func TestSleepWithContext_ZeroDuration(t *testing.T) {
409+
t.Parallel()
395410
ctx := context.Background()
396411
start := time.Now()
397412

@@ -405,6 +420,7 @@ func TestSleepWithContext_ZeroDuration(t *testing.T) {
405420

406421
// TestAPIRequest_RetryWithContextCancellation tests that context cancellation during backoff returns immediately
407422
func TestAPIRequest_RetryWithContextCancellation(t *testing.T) {
423+
t.Parallel()
408424
callCount := 0
409425

410426
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

internal/api/control_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
// TestControlEndpoints tests all simple control endpoints using table-driven approach
1212
func TestControlEndpoints(t *testing.T) {
13+
t.Parallel()
1314
tests := []struct {
1415
name string
1516
endpoint string
@@ -76,6 +77,7 @@ func TestControlEndpoints(t *testing.T) {
7677

7778
for _, tt := range tests {
7879
t.Run(tt.name, func(t *testing.T) {
80+
t.Parallel()
7981
server := createControlTestServer(t, "/"+tt.endpoint)
8082
defer server.Close()
8183

@@ -89,6 +91,7 @@ func TestControlEndpoints(t *testing.T) {
8991

9092
// TestSetHVACSetting tests setting HVAC settings
9193
func TestSetHVACSetting(t *testing.T) {
94+
t.Parallel()
9295
server := createControlTestServer(t, "/remoteServices/updateHVACSetting/v4")
9396
defer server.Close()
9497

@@ -100,6 +103,7 @@ func TestSetHVACSetting(t *testing.T) {
100103

101104
// TestSetHVACSetting_Fahrenheit tests setting HVAC with Fahrenheit
102105
func TestSetHVACSetting_Fahrenheit(t *testing.T) {
106+
t.Parallel()
103107
server := createControlTestServer(t, "/remoteServices/updateHVACSetting/v4")
104108
defer server.Close()
105109

@@ -111,6 +115,7 @@ func TestSetHVACSetting_Fahrenheit(t *testing.T) {
111115

112116
// TestControlError tests error handling for control endpoints
113117
func TestControlError(t *testing.T) {
118+
t.Parallel()
114119
server := createErrorServer(t, "500E00", "Internal error")
115120
defer server.Close()
116121

@@ -125,6 +130,7 @@ func TestControlError(t *testing.T) {
125130

126131
// TestBoolToInt tests the boolToInt helper function
127132
func TestBoolToInt(t *testing.T) {
133+
t.Parallel()
128134
tests := []struct {
129135
input bool
130136
want int

0 commit comments

Comments
 (0)