Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
go-version:
- "1.24"
- "1.25"
postgres-version: [17, 16, 15]
postgres-version: [18, 17, 16]
fail-fast: false
timeout-minutes: 5

Expand Down
23 changes: 16 additions & 7 deletions handler_api_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ type setupEndpointTestBundle struct {

func setupEndpoint[TEndpoint any](ctx context.Context, t *testing.T, initFunc func(bundle apibundle.APIBundle[pgx.Tx]) *TEndpoint) (*TEndpoint, *setupEndpointTestBundle) {
t.Helper()
return setupEndpointWithOpts(ctx, t, initFunc, nil)
}

func setupEndpointWithOpts[TEndpoint any](ctx context.Context, t *testing.T, initFunc func(bundle apibundle.APIBundle[pgx.Tx]) *TEndpoint, opts *riverdbtest.TestTxOpts) (*TEndpoint, *setupEndpointTestBundle) {
t.Helper()

var (
logger = riversharedtest.Logger(t)
driver = riverpgxv5.New(riversharedtest.DBPool(ctx, t))
tx, _ = riverdbtest.TestTxPgxDriver(ctx, t, driver, nil)
tx, _ = riverdbtest.TestTxPgxDriver(ctx, t, driver, opts)
exec = driver.UnwrapExecutor(tx)
)

Expand Down Expand Up @@ -234,9 +239,11 @@ func TestAPIHandlerFeaturesGet(t *testing.T) {

ctx := context.Background()

t.Run("SuccessWithEverythingFalse", func(t *testing.T) { //nolint:paralleltest
// This can't be parallelized because it tries to make DB schema changes.
endpoint, bundle := setupEndpoint(ctx, t, newFeaturesGetEndpoint)
t.Run("SuccessWithEverythingFalse", func(t *testing.T) {
t.Parallel()

// DisableSchemaSharing is required because we're making DB schema changes.
endpoint, bundle := setupEndpointWithOpts(ctx, t, newFeaturesGetEndpoint, &riverdbtest.TestTxOpts{DisableSchemaSharing: true})

_, err := bundle.tx.Exec(ctx, `DROP TABLE IF EXISTS river_client CASCADE;`)
require.NoError(t, err)
Expand All @@ -257,9 +264,11 @@ func TestAPIHandlerFeaturesGet(t *testing.T) {
}, resp)
})

t.Run("SuccessWithEverythingTrue", func(t *testing.T) { //nolint:paralleltest
// This can't be parallelized because it tries to make DB schema changes.
endpoint, bundle := setupEndpoint(ctx, t, newFeaturesGetEndpoint)
t.Run("SuccessWithEverythingTrue", func(t *testing.T) {
t.Parallel()

// DisableSchemaSharing is required because we're making DB schema changes.
endpoint, bundle := setupEndpointWithOpts(ctx, t, newFeaturesGetEndpoint, &riverdbtest.TestTxOpts{DisableSchemaSharing: true})

_, err := bundle.tx.Exec(ctx, `CREATE TABLE IF NOT EXISTS river_client (id SERIAL PRIMARY KEY);`)
require.NoError(t, err)
Expand Down
19 changes: 14 additions & 5 deletions internal/riveruicmd/auth_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
"riverqueue.com/riverui/uiendpoints"
)

func TestAuthMiddleware(t *testing.T) {
func TestAuthMiddleware(t *testing.T) { //nolint:tparallel
// Cannot be parallelized because of Setenv calls.
var (
ctx = context.Background()
databaseURL = cmp.Or(os.Getenv("TEST_DATABASE_URL"), "postgres://localhost/river_test")
Expand Down Expand Up @@ -49,7 +50,9 @@ func TestAuthMiddleware(t *testing.T) {
return initRes.httpServer.Handler
}

t.Run("Unauthorized", func(t *testing.T) { //nolint:paralleltest
t.Run("Unauthorized", func(t *testing.T) {
t.Parallel()

handler := setup(t, "/")
req := httptest.NewRequest(http.MethodGet, "/api/jobs", nil)
recorder := httptest.NewRecorder()
Expand All @@ -59,7 +62,9 @@ func TestAuthMiddleware(t *testing.T) {
require.Equal(t, http.StatusUnauthorized, recorder.Code)
})

t.Run("Authorized", func(t *testing.T) { //nolint:paralleltest
t.Run("Authorized", func(t *testing.T) {
t.Parallel()

handler := setup(t, "/")
req := httptest.NewRequest(http.MethodGet, "/api/jobs", nil)
req.SetBasicAuth(basicAuthUser, basicAuthPassword)
Expand All @@ -71,7 +76,9 @@ func TestAuthMiddleware(t *testing.T) {
require.Equal(t, http.StatusOK, recorder.Code)
})

t.Run("Healthcheck exemption", func(t *testing.T) { //nolint:paralleltest
t.Run("Healthcheck exemption", func(t *testing.T) {
t.Parallel()

handler := setup(t, "/")
req := httptest.NewRequest(http.MethodGet, "/api/health-checks/complete", nil)
recorder := httptest.NewRecorder()
Expand All @@ -81,7 +88,9 @@ func TestAuthMiddleware(t *testing.T) {
require.Equal(t, http.StatusOK, recorder.Code)
})

t.Run("Healthcheck exemption with prefix", func(t *testing.T) { //nolint:paralleltest
t.Run("Healthcheck exemption with prefix", func(t *testing.T) {
t.Parallel()

handler := setup(t, "/test-prefix")
req := httptest.NewRequest(http.MethodGet, "/test-prefix/api/health-checks/complete", nil)
recorder := httptest.NewRecorder()
Expand Down
20 changes: 13 additions & 7 deletions internal/riveruicmd/riveruicmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"riverqueue.com/riverui/uiendpoints"
)

func TestInitServer(t *testing.T) {
// TODO: this should be upgradeable to our latest test patterns to be parallelizable.
func TestInitServer(t *testing.T) { //nolint:tparallel
// Cannot be parallelized because of Setenv calls.
var (
ctx = context.Background()
databaseURL = cmp.Or(os.Getenv("TEST_DATABASE_URL"), "postgres://localhost/river_test")
Expand Down Expand Up @@ -51,14 +51,16 @@ func TestInitServer(t *testing.T) {
return initRes, &testBundle{}
}

t.Run("WithDatabaseURL", func(t *testing.T) { //nolint:paralleltest
t.Run("WithDatabaseURL", func(t *testing.T) {
t.Parallel()
initRes, _ := setup(t)

_, err := initRes.dbPool.Exec(ctx, "SELECT 1")
require.NoError(t, err)
})

t.Run("WithPGEnvVars", func(t *testing.T) {
t.Run("WithPGEnvVars", func(t *testing.T) { //nolint:paralleltest
// Cannot be parallelized because of Setenv calls.
t.Setenv("DATABASE_URL", "")

parsedURL, err := url.Parse(databaseURL)
Expand All @@ -79,7 +81,9 @@ func TestInitServer(t *testing.T) {
})

t.Run("JobListHideArgsByDefault", func(t *testing.T) {
t.Run("default value is false", func(t *testing.T) { //nolint:paralleltest
t.Run("DefaultValueIsFalse", func(t *testing.T) {
t.Parallel()

initRes, _ := setup(t)
req := httptest.NewRequest(http.MethodGet, "/api/features", nil)
recorder := httptest.NewRecorder()
Expand All @@ -94,7 +98,8 @@ func TestInitServer(t *testing.T) {
require.False(t, resp.JobListHideArgsByDefault)
})

t.Run("set to true with true", func(t *testing.T) {
t.Run("SetToTrueWithTrue", func(t *testing.T) { //nolint:paralleltest
// Cannot be parallelized because of Setenv calls.
t.Setenv("RIVER_JOB_LIST_HIDE_ARGS_BY_DEFAULT", "true")
initRes, _ := setup(t)
req := httptest.NewRequest(http.MethodGet, "/api/features", nil)
Expand All @@ -110,7 +115,8 @@ func TestInitServer(t *testing.T) {
require.True(t, resp.JobListHideArgsByDefault)
})

t.Run("set to true with 1", func(t *testing.T) {
t.Run("SetToTrueWith1", func(t *testing.T) { //nolint:paralleltest
// Cannot be parallelized because of Setenv calls.
t.Setenv("RIVER_JOB_LIST_HIDE_ARGS_BY_DEFAULT", "1")
initRes, _ := setup(t)
req := httptest.NewRequest(http.MethodGet, "/api/features", nil)
Expand Down
Loading