Skip to content

Add tests for providerch config, AWS instance mapping, and cmd provider init - #1143

Merged
cdalar merged 1 commit into
mainfrom
improve-coverage-0927
Sep 27, 2026
Merged

cdalar merged 1 commit into
mainfrom
improve-coverage-0927

Conversation

@cdalar

@cdalar cdalar commented Sep 27, 2026

Copy link
Copy Markdown
Owner

Summary

Adds unit tests for previously untested pure-logic code. Total statement coverage goes from 43.2% to 45.0%.

Package Before After
internal/providerch 33.3% 42.3%
cmd 33.0% 34.7%
pkg/cloud 44.7% 45.3%
  • internal/providerch/config_test.go:
    • expandHome, including leaving ~other/... untouched.
    • GetConfig defaults, including the chbr0 bridge address, kept separate from Firecracker's.
    • Explicit values: ch.os is normalized (" Windows " becomes windows).
    • The bridge/cidr shorthand and which value wins over ch.network.cidr.
  • pkg/cloud/aws_test.go: mapAwsServer field mapping, the name coming from the Name tag, and no nil dereference when a stopped or untagged instance has no IP or name.
  • cmd/root_provider_test.go:
    • resolveOvhServiceName rejects an empty value and the <service-name> placeholder.
    • ensureProvider reuses a provider that's already built.
    • initProvider builds fc, ch and static with config taken from viper.
    • findSingleFile falls back to the embedded file without network access.

Notes / follow-ups (not in this PR)

  • TestReadConfig_NoConfigDirectory and TestCreateFlagsBindToViper fail when a real ~/.onctl exists. This predates this PR; they pass with an isolated HOME.
  • TestFindSingleFile_EmbeddedFiles in cmd/coverage_test.go only asserts the function is non-nil, so it can't fail. The new TestFindSingleFile_EmbeddedFallback supersedes it.
  • NextApplyDir is left untested on purpose: it strips a leading /, which turns absolute paths into relative ones, and it calls log.Fatal on errors.

Test plan

  • go vet passes on the changed packages.
  • New tests pass.
  • go test ./cmd/ passes with an isolated HOME.

🤖 Generated with Claude Code

https://claude.ai/code/session_012KiUZoH8ZKKKuLfMg1Hgm8

…er init

Cover providerch expandHome/GetConfig (defaults, OS normalization, bridge/cidr
shorthand), mapAwsServer (Name tag, nil IPs on stopped/untagged instances),
and cmd resolveOvhServiceName, ensureProvider reuse, initProvider for the
local providers, and findSingleFile's embedded-file fallback.

Claude-Session: https://claude.ai/code/session_012KiUZoH8ZKKKuLfMg1Hgm8
@codecov

codecov Bot commented Sep 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 36.58%. Comparing base (4f2cb2c) to head (44978e4).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1143      +/-   ##
==========================================
+ Coverage   34.56%   36.58%   +2.01%     
==========================================
  Files          51       51              
  Lines        5612     5615       +3     
==========================================
+ Hits         1940     2054     +114     
+ Misses       3672     3561     -111     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cdalar
cdalar merged commit 81dbbde into main Sep 27, 2026
14 checks passed
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.

1 participant

⌂ 换网址