Przeglądaj źródła

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 11 godzin temu
rodzic
commit
5c1ab0bded

Plik diff jest za duży
+ 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) {
 func TestGetEntriesStablePaginationWithIdenticalPublishedDates(t *testing.T) {
 	t.Parallel()
 	t.Parallel()
 
 
-	testConfig := newIntegrationTestConfig()
-	if !testConfig.isConfigured() {
-		t.Skip(skipIntegrationTestsMessage)
-	}
+	testConfig := requireIntegrationTestConfig(t)
 
 
 	const (
 	const (
 		entryCount = 120
 		entryCount = 120
@@ -39,14 +36,7 @@ func TestGetEntriesStablePaginationWithIdenticalPublishedDates(t *testing.T) {
 	}))
 	}))
 	defer server.Close()
 	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 {
 	if _, err := client.CreateFeed(&miniflux.FeedCreationRequest{FeedURL: server.URL}); err != nil {
 		t.Fatal(err)
 		t.Fatal(err)
 	}
 	}

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików