Просмотр исходного кода

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 часов назад
Родитель
Сommit
5c1ab0bded
2 измененных файлов с 145 добавлено и 484 удалено
  1. 143 472
      internal/api/api_integration_test.go
  2. 2 12
      internal/api/entry_pagination_integration_test.go

Разница между файлами не показана из-за своего большого размера
+ 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)
 	}

Некоторые файлы не были показаны из-за большого количества измененных файлов