Skip to content

feat: extract browser.Browser interface for login provider testing#260

Open
briangann wants to merge 8 commits intomainfrom
feat/browser-interface-257
Open

feat: extract browser.Browser interface for login provider testing#260
briangann wants to merge 8 commits intomainfrom
feat/browser-interface-257

Conversation

@briangann
Copy link
Copy Markdown
Collaborator

@briangann briangann commented Apr 15, 2026

Summary

Closes #257

Features

  • Extract browser.Browser interface in pkg/browser/ to decouple login providers from chromedp
  • Add ChromeDP real implementation wrapping chromedp calls
  • Add recording Mock implementation for unit tests

Refactoring

  • Refactor GrafanaKioskAnonymous to accept browser.Browser for Navigate calls
  • Refactor GrafanaKioskLocal to accept browser.Browser, extract loginWithCredentials helper
  • Extract ActionFunc conditional logic from chromedp action chains into plain Go control flow

Tests

  • Add mock tests (15 assertions): call recording, error injection, counting, reset
  • Add anonymous login tests (4 assertions): URL generation, error propagation, reload
  • Add local login tests (24 assertions): loginWithCredentials sequence, error propagation, AutoLogin flow, direct flow

Scope

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 ./... passes
  • go vet ./... passes
  • npx markdownlint-cli2 CHANGELOG.md — 0 errors
  • npx cspell --config cspell.config.json "pkg/browser/*.go" — 0 issues
  • Mock correctly records Navigate, WaitVisible, Click, SendKeys calls
  • Mock error injection propagates to callers
  • loginWithCredentials calls WaitVisible then SendKeys twice in correct order
  • Anonymous and local login providers compile and existing tests pass

Code Metrics Report

Coverage Code to Test Ratio Test Execution Time
35.1% 1:0.9 3m11s

Code coverage of files in pull request scope (44.9%)

Files Coverage
pkg/browser/chromedp.go 0.0%
pkg/browser/mock.go 79.1%
pkg/cmd/grafana-kiosk/main.go 54.4%
pkg/kiosk/anonymous_login.go 0.0%
pkg/kiosk/local_login.go 20.3%

Reported by octocov

…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.
@briangann briangann force-pushed the feat/browser-interface-257 branch from e84866a to b629640 Compare April 15, 2026 16:41
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.

Extract CDP browser interface to enable login provider unit testing

1 participant