TestOIDC024UserCreation is flaky #884

Open
opened 2025-12-29 02:25:12 +01:00 by adam · 1 comment
Owner

Originally created by @kradalby on GitHub (Dec 16, 2024).

TestOIDC024UserCreation can flake because user order is not guaranteed, example: https://github.com/juanfont/headscale/actions/runs/12342220536/job/34441801242?pr=2298

We should make the output from the program (sort db output?) or something similar stable output.

Originally created by @kradalby on GitHub (Dec 16, 2024). TestOIDC024UserCreation can flake because user order is not guaranteed, example: https://github.com/juanfont/headscale/actions/runs/12342220536/job/34441801242?pr=2298 We should make the output from the program (sort db output?) or something similar stable output.
adam added the no-stale-bot label 2025-12-29 02:25:12 +01:00
Author
Owner

@ljluestc commented on GitHub (May 25, 2025):


package integration

import (
	"context"
	"sort"
	"testing"

	"github.com/juanfont/headscale/integration/hsic"
	"github.com/stretchr/testify/assert"
)

// TestOIDC024UserCreation tests the creation of users via OIDC.
func TestOIDC024UserCreation(t *testing.T) {
	// Setup the integration test context
	integration, err := hsic.NewTestingContext(t, nil)
	assert.NoError(t, err)
	defer integration.Close()

	// Simulate OIDC user creation
	// Replace with actual OIDC setup and user creation logic
	err = integration.CreateUser(context.Background(), "user1")
	assert.NoError(t, err)
	err = integration.CreateUser(context.Background(), "user2")
	assert.NoError(t, err)

	// Retrieve users from the database
	users, err := integration.ListUsers(context.Background())
	assert.NoError(t, err)

	// Sort users by Name to ensure deterministic order
	sort.Slice(users, func(i, j int) bool {
		return users[i].Name < users[j].Name
	})

	// Assert the users are as expected
	expectedUsers := []hsic.User{
		{Name: "user1"},
		{Name: "user2"},
	}
	assert.Equal(t, expectedUsers, users, "Users should match expected list in sorted order")
}

// ListUsers retrieves all users from the database.
// This is a placeholder; replace with actual database query logic.
func (i *hsic.TestingContext) ListUsers(ctx context.Context) ([]hsic.User, error) {
	var users []hsic.User
	// Replace with actual database query, e.g., using GORM or SQL
	// Example: i.DB.Find(&users)
	return users, nil
}

// CreateUser creates a user in the database.
// This is a placeholder; replace with actual OIDC user creation logic.
func (i *hsic.TestingContext) CreateUser(ctx context.Context, name string) error {
	// Replace with actual user creation logic, e.g., via OIDC flow
	return nil
}
@ljluestc commented on GitHub (May 25, 2025): ``` package integration import ( "context" "sort" "testing" "github.com/juanfont/headscale/integration/hsic" "github.com/stretchr/testify/assert" ) // TestOIDC024UserCreation tests the creation of users via OIDC. func TestOIDC024UserCreation(t *testing.T) { // Setup the integration test context integration, err := hsic.NewTestingContext(t, nil) assert.NoError(t, err) defer integration.Close() // Simulate OIDC user creation // Replace with actual OIDC setup and user creation logic err = integration.CreateUser(context.Background(), "user1") assert.NoError(t, err) err = integration.CreateUser(context.Background(), "user2") assert.NoError(t, err) // Retrieve users from the database users, err := integration.ListUsers(context.Background()) assert.NoError(t, err) // Sort users by Name to ensure deterministic order sort.Slice(users, func(i, j int) bool { return users[i].Name < users[j].Name }) // Assert the users are as expected expectedUsers := []hsic.User{ {Name: "user1"}, {Name: "user2"}, } assert.Equal(t, expectedUsers, users, "Users should match expected list in sorted order") } // ListUsers retrieves all users from the database. // This is a placeholder; replace with actual database query logic. func (i *hsic.TestingContext) ListUsers(ctx context.Context) ([]hsic.User, error) { var users []hsic.User // Replace with actual database query, e.g., using GORM or SQL // Example: i.DB.Find(&users) return users, nil } // CreateUser creates a user in the database. // This is a placeholder; replace with actual OIDC user creation logic. func (i *hsic.TestingContext) CreateUser(ctx context.Context, name string) error { // Replace with actual user creation logic, e.g., via OIDC flow return nil } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/headscale#884