Skip to content

Refactoring tests in kratos package - #846

Open
shipperizer wants to merge 2 commits into
mainfrom
test/kratos
Open

Refactoring tests in kratos package#846
shipperizer wants to merge 2 commits into
mainfrom
test/kratos

Conversation

@shipperizer

Copy link
Copy Markdown
Collaborator

No description provided.

@shipperizer
shipperizer requested a review from a team as a code owner February 2, 2026 15:43
Copilot AI review requested due to automatic review settings February 2, 2026 15:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors test functions in the kratos package by consolidating multiple individual test functions into table-driven tests, improving test maintainability and reducing code duplication.

Changes:

  • Consolidated multiple test functions into table-driven tests with subtests using t.Run
  • Reduced test code duplication by parameterizing test cases
  • Improved test organization and readability

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

File Description
pkg/kratos/handlers_test.go Refactored handler tests into table-driven format, consolidating tests for flow creation, session handling, login/recovery flows, and update operations
pkg/kratos/cookies_test.go Refactored cookie manager tests into table-driven format, consolidating state cookie operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +32 to 38
tests := []struct {
name string
}{
{
name: "ClearState",
},
}

Copilot AI Feb 2, 2026

Copy link

Choose a reason for hiding this comment

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

The table-driven test structure for TestAuthCookieManager_ClearStateCookie contains only a single test case with no variations. This adds unnecessary complexity without benefit. Either add multiple test cases to justify the table-driven approach, or revert to a simple test function.

Copilot uses AI. Check for mistakes.
Comment on lines +110 to +117
if tt.requestCookie == nil {
mockEncrypt = nil
}
if mockEncrypt != nil {
tt.setupMocks(mockEncrypt, mockLogger)
} else {
tt.setupMocks(nil, mockLogger)
}

Copilot AI Feb 2, 2026

Copy link

Choose a reason for hiding this comment

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

The conditional logic reassigning mockEncrypt to nil and then passing it to setupMocks is convoluted. Consider having setupMocks handle nil cases directly, or restructure to avoid reassigning the mock variable after initialization.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants