Skip to content

Conversation

@wagnerdevocelot
Copy link
Owner

Summary

  • add sqlite driver dependency
  • unit tests for LegacyDBAdapter
  • unit tests for LoggingAdapter
  • integration test using the legacy DB
  • performance benchmarks for token creation
  • fix benchmark context to use context.Background

Testing

  • go vet ./...
  • go test ./... -v
  • go test -bench=. -run=NONE

https://chatgpt.com/codex/tasks/task_e_687443f066ac832881de289ac38519fa

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive testing and benchmarking support for both the in-memory and legacy database adapters, and includes the SQLite driver dependency.

  • Adds github.com/mattn/go-sqlite3 in go.mod for DB tests.
  • Expands unit tests for LegacyDBAdapter and LoggingAdapter, including error paths and metrics.
  • Introduces a full integration test for the OAuth2 flow against the legacy DB and performance benchmarks for token creation.

Reviewed Changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
logging_adapter_test.go Unit tests for LoggingAdapter metrics and error increment logic
integration_legacy_db_test.go Full OAuth2 authorization code flow against LegacyDBAdapter
go.mod Added SQLite driver dependency
db_adapter_test.go Unit tests for LegacyDBAdapter client, token, session, and JWT
benchmark_test.go Benchmarks for token creation in in-memory and legacy adapters

}

metrics := adapter.Metrics()
expected := []string{"CreateClient", "GetClient", "UpdateClient", "DeleteClient", "CreateToken", "GetToken", "RevokeToken", "DeleteToken", "CreateSession", "GetSession", "DeleteSession", "ValidateJWT", "MarkJWTAsUsed", "CreatePKCESession", "GetPKCESession", "DeletePKCESession"}
Copy link

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expected metric names for PKCE sessions (CreatePKCESession, GetPKCESession, DeletePKCESession) do not match the adapter's actual method names (CreatePKCERequestSession, GetPKCERequestSession, DeletePKCERequestSession). Update the expected keys to match the correct method names.

Suggested change
expected := []string{"CreateClient", "GetClient", "UpdateClient", "DeleteClient", "CreateToken", "GetToken", "RevokeToken", "DeleteToken", "CreateSession", "GetSession", "DeleteSession", "ValidateJWT", "MarkJWTAsUsed", "CreatePKCESession", "GetPKCESession", "DeletePKCESession"}
expected := []string{"CreateClient", "GetClient", "UpdateClient", "DeleteClient", "CreateToken", "GetToken", "RevokeToken", "DeleteToken", "CreateSession", "GetSession", "DeleteSession", "ValidateJWT", "MarkJWTAsUsed", "CreatePKCERequestSession", "GetPKCERequestSession", "DeletePKCERequestSession"}

Copilot uses AI. Check for mistakes.
if _, err := db.Exec(s); err != nil {
b.Fatal(err)
}
}
Copy link

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The benchmark setup (opening DB and creating tables) is included in the measurement; to focus the benchmark on token creation only, call b.ResetTimer() after setup and before the measurement loop.

Suggested change
}
}
b.ResetTimer()

Copilot uses AI. Check for mistakes.
"github.com/ory/fosite"
)

func setupTestDB(t *testing.T) *sql.DB {
Copy link

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The in-memory database opened here is never closed, which can lead to resource leaks. Consider using t.Cleanup to close the database before tests complete (e.g., t.Cleanup(func() { db.Close() })).

Copilot uses AI. Check for mistakes.
"github.com/ory/fosite/token/jwt"
)

// setupLegacyStore initializes the global store with a LoggingAdapter over LegacyDBAdapter.
Copy link

Copilot AI Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment mentions wrapping the store with a LoggingAdapter, but the code uses NewLegacyDBAdapter directly. Either wrap with NewLoggingAdapter(NewLegacyDBAdapter(db)) or update the comment to reflect the actual behavior.

Copilot uses AI. Check for mistakes.
@wagnerdevocelot wagnerdevocelot merged commit bb1ac7f into main Jul 14, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants