feat: extract browser.Browser interface for login provider testing#260
Open
feat: extract browser.Browser interface for login provider testing#260
Conversation
…lity
Add browser.Browser parameter to GrafanaKioskAnonymous, replacing direct
chromedp.Navigate calls with b.Navigate so the function can be exercised
with a mock in unit tests. Update main.go to pass &browser.ChromeDP{} at
the call site.
Tests verify Navigate is called with the generated URL, errors are propagated, and a reload triggers a second Navigate call.
Extract loginWithCredentials helper and replace chromedp action chains with browser.Browser interface calls, matching the anonymous login pattern.
Tests cover loginWithCredentials (happy path, WaitVisible error propagation, SendKeys error propagation) and the auto-login and direct-login flow patterns using the browser.Mock.
e84866a to
b629640
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #257
Features
browser.Browserinterface inpkg/browser/to decouple login providers from chromedpChromeDPreal implementation wrapping chromedp callsMockimplementation for unit testsRefactoring
GrafanaKioskAnonymousto acceptbrowser.Browserfor Navigate callsGrafanaKioskLocalto acceptbrowser.Browser, extractloginWithCredentialshelperActionFuncconditional logic from chromedp action chains into plain Go control flowTests
loginWithCredentialssequence, error propagation, AutoLogin flow, direct flowScope
This is phase 1 — proof of concept with anonymous and local providers. Remaining 6 providers (gcom, goauth, idtoken, apikey, aws, azuread) will be migrated in a follow-up.
Test plan
go test ./...passesgo vet ./...passesnpx markdownlint-cli2 CHANGELOG.md— 0 errorsnpx cspell --config cspell.config.json "pkg/browser/*.go"— 0 issuesloginWithCredentialscalls WaitVisible then SendKeys twice in correct orderCode Metrics Report
Code coverage of files in pull request scope (44.9%)
Reported by octocov