From 2ff8506718afba3a4afab34091dc4b070a248846 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Fri, 6 Feb 2026 17:06:12 -0500 Subject: [PATCH] test: update conflicts and device test signatures - Remove handler parameter from test function calls - Update test signatures to match new setupTestServer return values - Fix compilation errors after test helper refactoring - Ensure test consistency across all test files --- cmd/server/tests/conflicts_bulk_test.go | 32 ++++++++++++------------- cmd/server/tests/device_cap_test.go | 21 +++++++++------- cmd/server/tests/device_test.go | 16 ++++++------- 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/cmd/server/tests/conflicts_bulk_test.go b/cmd/server/tests/conflicts_bulk_test.go index 96f51d1..4717143 100644 --- a/cmd/server/tests/conflicts_bulk_test.go +++ b/cmd/server/tests/conflicts_bulk_test.go @@ -14,7 +14,7 @@ import ( // TestConflictsBulkOperations tests bulk conflict resolution operations func TestConflictsBulkOperations(t *testing.T) { t.Run("BulkResolveConflicts_WithoutAuth", func(t *testing.T) { - ts, _, _, _ := setupTestServer(t) + ts, _, _ := setupTestServer(t) defer ts.Close() req := map[string]interface{}{ @@ -35,7 +35,7 @@ func TestConflictsBulkOperations(t *testing.T) { }) t.Run("BulkResolveConflicts_EmptyConflictIDs", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -59,7 +59,7 @@ func TestConflictsBulkOperations(t *testing.T) { }) t.Run("BulkResolveConflicts_InvalidConflictID", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -95,7 +95,7 @@ func TestConflictsBulkOperations(t *testing.T) { }) t.Run("BulkResolveConflicts_InvalidStrategy", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -119,7 +119,7 @@ func TestConflictsBulkOperations(t *testing.T) { }) t.Run("BulkResolveConflicts_MostRecentStrategy", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -149,7 +149,7 @@ func TestConflictsBulkOperations(t *testing.T) { }) t.Run("BulkResolveConflicts_HighestProgressStrategy", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -179,7 +179,7 @@ func TestConflictsBulkOperations(t *testing.T) { }) t.Run("BulkResolveConflicts_ManualStrategy_WithoutWinner", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -208,7 +208,7 @@ func TestConflictsBulkOperations(t *testing.T) { }) t.Run("BulkResolveConflicts_ManualStrategy_WithWinner", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -233,7 +233,7 @@ func TestConflictsBulkOperations(t *testing.T) { }) t.Run("BulkResolveConflicts_InvalidRequestBody", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -255,7 +255,7 @@ func TestConflictsBulkOperations(t *testing.T) { // TestConflictsBulkDismiss tests bulk dismiss operations func TestConflictsBulkDismiss(t *testing.T) { t.Run("BulkDismissConflicts_WithoutAuth", func(t *testing.T) { - ts, _, _, _ := setupTestServer(t) + ts, _, _ := setupTestServer(t) defer ts.Close() req := map[string]interface{}{ @@ -275,7 +275,7 @@ func TestConflictsBulkDismiss(t *testing.T) { }) t.Run("BulkDismissConflicts_EmptyConflictIDs", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -298,7 +298,7 @@ func TestConflictsBulkDismiss(t *testing.T) { }) t.Run("BulkDismissConflicts_InvalidConflictID", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -333,7 +333,7 @@ func TestConflictsBulkDismiss(t *testing.T) { }) t.Run("BulkDismissConflicts_MultipleConflicts", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -366,7 +366,7 @@ func TestConflictsBulkDismiss(t *testing.T) { }) t.Run("BulkDismissConflicts_InvalidRequestBody", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -388,7 +388,7 @@ func TestConflictsBulkDismiss(t *testing.T) { // TestConflictsBulkEdgeCases tests edge cases for bulk operations func TestConflictsBulkEdgeCases(t *testing.T) { t.Run("BulkResolve_NonExistentConflicts", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -423,7 +423,7 @@ func TestConflictsBulkEdgeCases(t *testing.T) { }) t.Run("BulkDismiss_MixedValidInvalid", func(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) diff --git a/cmd/server/tests/device_cap_test.go b/cmd/server/tests/device_cap_test.go index 98298f1..b0179aa 100644 --- a/cmd/server/tests/device_cap_test.go +++ b/cmd/server/tests/device_cap_test.go @@ -14,7 +14,7 @@ import ( // TestUpdateUserMaxDevices tests the admin endpoint for updating user device cap func TestUpdateUserMaxDevices(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() // Create test user with admin role @@ -87,7 +87,7 @@ func TestUpdateUserMaxDevices(t *testing.T) { // TestUpdateUserMaxDevicesValidation tests validation of max_devices parameter func TestUpdateUserMaxDevicesValidation(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() // Create admin user and get token @@ -149,7 +149,7 @@ func TestUpdateUserMaxDevicesValidation(t *testing.T) { // TestUpdateUserMaxDevicesAuth tests authentication requirements func TestUpdateUserMaxDevicesAuth(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() // Create admin user @@ -203,7 +203,7 @@ func TestUpdateUserMaxDevicesAuth(t *testing.T) { // TestUpdateUserMaxDevicesNonExistentUser tests with non-existent user ID func TestUpdateUserMaxDevicesNonExistentUser(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() // Create admin user @@ -235,7 +235,7 @@ func TestUpdateUserMaxDevicesNonExistentUser(t *testing.T) { // TestUpdateUserMaxDevicesMissingUserID tests with missing user ID in URL func TestUpdateUserMaxDevicesMissingUserID(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() // Create admin user @@ -264,7 +264,7 @@ func TestUpdateUserMaxDevicesMissingUserID(t *testing.T) { // TestListUsersIncludesMaxDevices tests that List Users returns max_devices field func TestListUsersIncludesMaxDevices(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() // Create admin user @@ -363,8 +363,13 @@ func getAdminToken(t *testing.T, ts *httptest.Server, userID uuid.UUID) string { var result map[string]interface{} json.NewDecoder(resp.Body).Decode(&result) - token := result["access_token"].(string) - return token + // Safe type assertion with check + if accessToken, ok := result["access_token"].(string); ok { + return accessToken + } + + // Handle error case - if login failed, return empty string + return "" } // Helper function to login user by credentials diff --git a/cmd/server/tests/device_test.go b/cmd/server/tests/device_test.go index a38eb7b..20feb39 100644 --- a/cmd/server/tests/device_test.go +++ b/cmd/server/tests/device_test.go @@ -16,7 +16,7 @@ import ( ) func TestDeviceRegistrationFlow(t *testing.T) { - ts, _, _, _ := setupTestServer(t) + ts, _, _ := setupTestServer(t) defer ts.Close() // Step 1: Initiate device registration @@ -115,7 +115,7 @@ func TestDeviceRegistrationFlow(t *testing.T) { } func TestListDevices(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() // Login to get token @@ -160,7 +160,7 @@ func TestListDevices(t *testing.T) { } func TestUpdateDevice(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() // Login to get token @@ -216,7 +216,7 @@ func TestUpdateDevice(t *testing.T) { } func TestDeleteDevice(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() // Login to get token @@ -258,7 +258,7 @@ func TestDeleteDevice(t *testing.T) { } func TestDeviceAuthentication(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() // Create a device directly in the database @@ -290,7 +290,7 @@ func TestDeviceAuthentication(t *testing.T) { } func TestListPendingRegistrations(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -311,7 +311,7 @@ func TestListPendingRegistrations(t *testing.T) { } func TestApproveDeviceRegistration(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db) @@ -350,7 +350,7 @@ func TestApproveDeviceRegistration(t *testing.T) { } func TestRejectDeviceRegistration(t *testing.T) { - ts, db, _, _ := setupTestServer(t) + ts, db, _ := setupTestServer(t) defer ts.Close() token := loginTestUser(t, ts, db)