Explorar el Código

test(api): add integration test helpers with checked cleanup

Every integration test repeated the same setup: a skip check, an admin
client, and a throwaway regular user removed with a deferred
DeleteUser call whose error was ignored. Since user deletion is
synchronous and reports failures, cleanup problems went unnoticed.

Add helpers to the integration test config:

- requireIntegrationTestConfig skips the test when the TEST_MINIFLUX_*
  variables are not set.
- newAdminClient returns a client authenticated as the admin.
- newRegularUser creates a user and returns a client authenticated as
  that user.
- deleteUserOnCleanup removes the user with t.Cleanup and fails the
  test if the deletion fails.

Cleanup now runs after subtests finish instead of when the test
function returns. Convert the API and pagination integration tests to
use the helpers without changing what they assert.
Fred hace 7 horas
padre
commit
5c1ab0bded
Se han modificado 2 ficheros con 145 adiciones y 484 borrados
  1. 143 472
      internal/api/api_integration_test.go
  2. 2 12
      internal/api/entry_pagination_integration_test.go

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 143 - 472
internal/api/api_integration_test.go


+ 2 - 12
internal/api/entry_pagination_integration_test.go

@@ -17,10 +17,7 @@ import (
 func TestGetEntriesStablePaginationWithIdenticalPublishedDates(t *testing.T) {
 	t.Parallel()
 
-	testConfig := newIntegrationTestConfig()
-	if !testConfig.isConfigured() {
-		t.Skip(skipIntegrationTestsMessage)
-	}
+	testConfig := requireIntegrationTestConfig(t)
 
 	const (
 		entryCount = 120
@@ -39,14 +36,7 @@ func TestGetEntriesStablePaginationWithIdenticalPublishedDates(t *testing.T) {
 	}))
 	defer server.Close()
 
-	adminClient := miniflux.NewClient(testConfig.testBaseURL, testConfig.testAdminUsername, testConfig.testAdminPassword)
-	user, err := adminClient.CreateUser(testConfig.genRandomUsername(), testConfig.testRegularPassword, false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	defer adminClient.DeleteUser(user.ID)
-
-	client := miniflux.NewClient(testConfig.testBaseURL, user.Username, testConfig.testRegularPassword)
+	client, _ := testConfig.newRegularUser(t)
 	if _, err := client.CreateFeed(&miniflux.FeedCreationRequest{FeedURL: server.URL}); err != nil {
 		t.Fatal(err)
 	}

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio