From 291b50d13100cb395187e3b7c514e514e41db661 Mon Sep 17 00:00:00 2001 From: pasha1coil Date: Mon, 14 Jul 2025 10:45:19 +0300 Subject: [PATCH] - --- tests/main_test.go | 390 --------------------------------------------- 1 file changed, 390 deletions(-) diff --git a/tests/main_test.go b/tests/main_test.go index 4bd16fc..22a3f43 100644 --- a/tests/main_test.go +++ b/tests/main_test.go @@ -217,38 +217,6 @@ func TestGetAccount_BoundaryCases(t *testing.T) { }) } -// todo error_simulation_token -func TestGetAccount_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - req, err := http.NewRequest("GET", baseURL+"/account/get", nil) - assert.NoError(t, err) - req.Header.Set("Authorization", "Bearer "+"error_simulation_token") - - resp, err := http.DefaultClient.Do(req) - assert.NoError(t, err) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - - t.Run("TimeoutHandling", func(t *testing.T) { - client := &http.Client{Timeout: 1 * time.Millisecond} - - req, err := http.NewRequest("GET", baseURL+"/account/get", nil) - assert.NoError(t, err) - req.Header.Set("Authorization", "Bearer "+validToken) - - _, err = client.Do(req) - assert.Error(t, err) - assert.Contains(t, err.Error(), "timeout") - }) -} - func TestGetAccount_SpecialCases(t *testing.T) { t.Run("AccountWithoutPrivileges", func(t *testing.T) { req, err := http.NewRequest("GET", baseURL+"/account/get", nil) @@ -421,20 +389,6 @@ func TestCreateAccount(t *testing.T) { assert.NoError(t, err) assert.Equal(t, unicodeUserID, result["user_id"]) }) - // todo error_simulation_token - t.Run("ErrorHandling_InternalServerError", func(t *testing.T) { - resp := createAccountRequest(t, "error_simulation_token", map[string]interface{}{ - "user_id": "test_user", - }) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err := json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) t.Run("ErrorHandling_Timeout", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} @@ -677,25 +631,7 @@ func TestDeleteAccount_BoundaryCases(t *testing.T) { }) } -// todo error_simulation_token func TestDeleteAccount_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - req, err := http.NewRequest("DELETE", baseURL+"/account/delete", nil) - assert.NoError(t, err) - req.Header.Set("Authorization", "Bearer "+"error_simulation_token") - - resp, err := http.DefaultClient.Do(req) - assert.NoError(t, err) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} @@ -985,33 +921,7 @@ func TestGetAccounts_BoundaryCases(t *testing.T) { }) } -// todo error_simulation_token func TestGetAccounts_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - // Имитируем сбой базы данных - body := map[string]interface{}{ - "limit": 10, - "page": 1, - } - b, err := json.Marshal(body) - assert.NoError(t, err) - req, err := http.NewRequest("GET", baseURL+"/accounts", bytes.NewReader(b)) - assert.NoError(t, err) - req.Header.Set("Authorization", "Bearer "+"error_simulation_token") - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - assert.NoError(t, err) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} @@ -1303,29 +1213,7 @@ func TestGetPrivilege_Performance(t *testing.T) { }) } -// todo error_simulation_token func TestGetPrivilege_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - body := map[string]string{"userId": existingUserID} - data, err := json.Marshal(body) - assert.NoError(t, err) - req, err := http.NewRequest("GET", baseURL+"/privilege/"+existingUserID, bytes.NewBuffer(data)) - assert.NoError(t, err) - req.Header.Set("Authorization", "Bearer "+"error_simulation_token") - req.Header.Set("Content-Type", "application/json") - - resp, err := http.DefaultClient.Do(req) - assert.NoError(t, err) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} @@ -1535,21 +1423,7 @@ func TestDeleteAccountByUserID_SQLInjection_XSS(t *testing.T) { }) } -// todo error_simulation_token func TestDeleteAccountByUserID_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := deleteAccountByUserIDRequest("error_simulation_token", map[string]string{"userId": userIDForDelete}) - assert.NoError(t, err) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} @@ -1740,20 +1614,7 @@ func TestManualDone_Security(t *testing.T) { }) } -// todo error_simulation_token func TestManualDone_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := manualDoneRequest("error_simulation_token", map[string]string{"id": testUserID}) - assert.NoError(t, err) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} @@ -1984,25 +1845,7 @@ func TestCreateLeadTarget_BoundaryCases(t *testing.T) { }) } -// todo error_simulation_token func TestCreateLeadTarget_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := createLeadTargetRequest("error_simulation_token", map[string]interface{}{ - "type": "mail", - "quizID": 123, - "target": "example@mail.com", - }) - assert.NoError(t, err) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} @@ -2325,21 +2168,7 @@ func TestUpdateLeadTarget_BoundaryCases(t *testing.T) { }) } -// todo error_simulation_token func TestDeleteLeadTarget_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := deleteLeadTargetRequest("error_simulation_token", "123") - assert.NoError(t, err) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} @@ -2556,21 +2385,7 @@ func TestDeleteLeadTarget_AlreadyDeleted(t *testing.T) { assert.Equal(t, http.StatusOK, resp2.StatusCode) } -// todo error_simulation_token func TestGetLeadTargetByQuizID_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := getLeadTargetByQuizIDRequest("error_simulation_token", "123") - assert.NoError(t, err) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} @@ -2752,25 +2567,7 @@ func TestGetLeadTargetByQuizID_DeletedTarget(t *testing.T) { assert.Equal(t, http.StatusNotFound, resp.StatusCode) } -// todo error_simulation_token func TestCreateQuestion_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := createQuestionRequest("error_simulation_token", map[string]interface{}{ - "quiz_id": 12345, - "title": "Test Question", - "type": "variant", - }) - assert.NoError(t, err) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} @@ -3054,24 +2851,7 @@ func TestCreateQuestion_BoundaryCases(t *testing.T) { }) } -// todo error_simulation_token func TestGetQuestionList_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := getQuestionListRequest("error_simulation_token", map[string]interface{}{ - "limit": 10, - "page": 1, - }) - assert.NoError(t, err) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} @@ -3416,24 +3196,7 @@ func TestGetQuestionList_Performance(t *testing.T) { }) } -// todo error_simulation_token func TestEditQuestion_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := editQuestionRequest("error_simulation_token", map[string]interface{}{ - "id": 123, - "title": "Test Question", - }) - assert.NoError(t, err) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} @@ -3778,24 +3541,7 @@ func TestEditQuestion_Performance(t *testing.T) { }) } -// todo error_simulation_token func TestCopyQuestion_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := copyQuestionRequest("error_simulation_token", map[string]interface{}{ - "id": 101, - "quiz_id": 202, - }) - assert.NoError(t, err) - defer resp.Body.Close() - - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} @@ -4099,23 +3845,7 @@ func TestCopyQuestion_OriginalPreserved(t *testing.T) { assert.Equal(t, originalTitle, copyResult["title"]) } -// todo error_simulation_token func TestGetQuestionHistory_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := getQuestionHistoryRequest("error_simulation_token", map[string]interface{}{ - "id": 101, - "l": 10, - "p": 1, - }) - assert.NoError(t, err) - defer resp.Body.Close() - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} payload, err := json.Marshal(map[string]interface{}{ @@ -4496,21 +4226,7 @@ func TestGetQuestionHistory_Performance(t *testing.T) { }) } -// todo error_simulation_token func TestDeleteQuestion_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := deleteQuestionRequest("error_simulation_token", map[string]interface{}{ - "id": 101, - }) - assert.NoError(t, err) - defer resp.Body.Close() - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} payload, err := json.Marshal(map[string]interface{}{ @@ -4753,21 +4469,7 @@ func TestDeleteQuestion_Performance(t *testing.T) { }) } -// todo error_simulation_token func TestCreateQuiz_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := createQuizRequest("error_simulation_token", map[string]interface{}{ - "name": "Test Quiz", - }) - assert.NoError(t, err) - defer resp.Body.Close() - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} payload, err := json.Marshal(map[string]interface{}{ @@ -5117,22 +4819,7 @@ func TestCreateQuiz_SuperQuiz(t *testing.T) { }) } -// todo error_simulation_token func TestGetQuizList_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := getQuizListRequest("error_simulation_token", map[string]interface{}{ - "limit": 10, - "page": 1, - }) - assert.NoError(t, err) - defer resp.Body.Close() - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} payload, err := json.Marshal(map[string]interface{}{ @@ -5593,23 +5280,6 @@ func TestGetQuizList_Performance(t *testing.T) { }) } -// todo error_simulation_token -func TestEditQuiz_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := editQuizRequest("error_simulation_token", map[string]interface{}{ - "id": 101, - "name": "Test Quiz", - }) - assert.NoError(t, err) - defer resp.Body.Close() - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) -} - func editQuizRequest(token string, body map[string]interface{}) (*http.Response, error) { payload, err := json.Marshal(body) if err != nil { @@ -5860,22 +5530,6 @@ func TestEditQuiz_Performance(t *testing.T) { }) } -// todo error_simulation_token -func TestCopyQuiz_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := copyQuizRequest("error_simulation_token", map[string]interface{}{ - "id": 101, - }) - assert.NoError(t, err) - defer resp.Body.Close() - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) -} - func copyQuizRequest(token string, body map[string]interface{}) (*http.Response, error) { payload, err := json.Marshal(body) if err != nil { @@ -6033,23 +5687,7 @@ func TestCopyQuiz_Performance(t *testing.T) { }) } -// todo error_simulation_token func TestGetQuizHistory_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := getQuizHistoryRequest("error_simulation_token", map[string]interface{}{ - "id": 101, - "l": 10, - "p": 1, - }) - assert.NoError(t, err) - defer resp.Body.Close() - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} payload, err := json.Marshal(map[string]interface{}{ @@ -6386,21 +6024,7 @@ func TestGetQuizHistory_Performance(t *testing.T) { }) } -// todo error_simulation_token func TestDeleteQuiz_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := deleteQuizRequest("error_simulation_token", map[string]interface{}{ - "id": 101, - }) - assert.NoError(t, err) - defer resp.Body.Close() - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} payload, err := json.Marshal(map[string]interface{}{ @@ -6599,21 +6223,7 @@ func TestDeleteQuiz_Performance(t *testing.T) { }) } -// todo error_simulation_token func TestArchiveQuiz_ErrorHandling(t *testing.T) { - t.Run("InternalServerError", func(t *testing.T) { - resp, err := archiveQuizRequest("error_simulation_token", map[string]interface{}{ - "id": 101, - }) - assert.NoError(t, err) - defer resp.Body.Close() - assert.Equal(t, http.StatusInternalServerError, resp.StatusCode) - var errorResponse map[string]interface{} - err = json.NewDecoder(resp.Body).Decode(&errorResponse) - assert.NoError(t, err) - assert.Contains(t, errorResponse, "error") - }) - t.Run("TimeoutHandling", func(t *testing.T) { client := &http.Client{Timeout: 1 * time.Millisecond} payload, err := json.Marshal(map[string]interface{}{