Skip to content

Feat/more test coverage#760

Open
muhahahmad68 wants to merge 2 commits intodotandev:mainfrom
muhahahmad68:feat/more-test-coverage
Open

Feat/more test coverage#760
muhahahmad68 wants to merge 2 commits intodotandev:mainfrom
muhahahmad68:feat/more-test-coverage

Conversation

@muhahahmad68
Copy link
Contributor

Overview

Achieves 90%+ branch coverage on the self-upgrade utilities in internal/updater, covering all previously untested error paths, HTTP integration branches, cache failure modes, and configuration parsing edge cases.

Changes

Core Implementation

  • checker.go: Added apiURL string field to Checker struct
    • One-line branch in fetchLatestVersion uses apiURL when set, falls back to GitHubAPIURL
    • Enables full HTTP path testing without hitting the real GitHub API
    • Zero behaviour change for production callers — NewChecker never sets apiURL

Testing

  • checker_coverage_test.go: New test file covering all 23 previously-uncovered branches

    fetchLatestVersion

    • Success path returns correct tag name with proper User-Agent header
    • Non-200 status (403, 429) returns structured error
    • Malformed JSON body returns parse error
    • Dead server (connection refused) returns network error
    • Cancelled context returns context error

    compareVersions

    • Unparseable current version returns error
    • Unparseable latest version returns error

    updateCache

    • File blocking cache directory returns MkdirAll error
    • Read-only cache directory returns WriteFile error
    • Both cases skipped when running as root

    CheckForUpdates integration

    • Update available → notification printed to stderr
    • No update needed → no output produced
    • API error → no output, no panic
    • Disabled by ERST_NO_UPDATE_CHECK → API never called
    • Fresh cache → API never called

    checkConfigFile

    • check_for_updates: true does not disable
    • No matching key does not disable
    • Empty file does not disable
    • Comment line is skipped
    • Value with surrounding whitespace is handled correctly
    • Multiple keys, false value is respected

    isUpdateCheckDisabled

    • Empty configPath fallthrough returns false without panic

    getCacheDir / getConfigPath

    • Always return a non-empty path containing erst on supported platforms
    • Neither panics under any environment

Coverage

  • All code paths tested without lint suppressions
  • Tests are hermetic: every test that touches the filesystem uses t.TempDir()
  • Every test that sets environment variables uses t.Setenv() for automatic cleanup
  • HTTP tests use httptest.NewServer — no network required

Verification

go test ./internal/updater/... -v -count=1
go test ./internal/updater/... -coverprofile=coverage.out
go tool cover -func=coverage.out | grep total

Related Issues

Closes #425

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Test coverage improvement

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Tests added — 23 new branch paths covered
  • No new linting issues
  • No lint suppressions added
  • All tests are hermetic (no shared state, no real network calls)
  • Backward compatible — apiURL field is unexported and zero-valued in production

@dotandev
Copy link
Owner

fix conflicts, please.

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.

[DEPS] Setup dependabot for Rust & Go modules #212

2 participants