Skip to content

test: extend cloud, config, and image package test coverage#138

Merged
larkly merged 1 commit intomainfrom
features/test-coverage-cloud-config-image
Apr 7, 2026
Merged

test: extend cloud, config, and image package test coverage#138
larkly merged 1 commit intomainfrom
features/test-coverage-cloud-config-image

Conversation

@larkly
Copy link
Copy Markdown
Owner

@larkly larkly commented Apr 6, 2026

Summary

Extended test coverage across 3 core packages with 30 new tests.

cloud/clouds_test.go (+8 tests, was 3 → now 11)

  • TestCloudsYamlPaths_Order - validates search path priority order
  • TestCloudsYamlPaths_WithEnv / TestCloudsYamlPaths_WithoutEnv - env var handling
  • TestListCloudNames_InvalidYAML - malformed YAML error handling
  • TestListCloudNames_NoCloudsKey - missing clouds key returns empty list
  • TestListCloudNames_EmptyFile - empty file handling
  • TestListCloudNames_Precedence - OS_CLIENT_CONFIG_FILE takes precedence
  • TestListCloudNames_DetailedCloudsYaml - multi-cloud YAML with full auth fields

config/config_test.go (+10 tests, was 7 → now 17)

  • TestEmptyConfigFile - empty file returns defaults
  • TestMalformedYAMLConfig - invalid YAML returns error
  • TestPartialConfigOnlyColors - partial config fills missing sections from defaults
  • TestPartialConfigOnlyKeybindings - keybinding-only config properly merged
  • TestSaveToCreatesParentDirectories - nested directory creation
  • TestKeybindingsEmptyMap - empty map filled from defaults
  • TestConfigWithOnlyGeneralSection - general-only config with full color/keybinding defaults
  • TestMergeAllCLIFlags - all CLI flag override combinations
  • TestSaveAndRoundTrip - write then read then verify all fields preserved

image/images_test.go (+12 tests, was 0 → now 12)

  • TestProgressReader - basic read, data chunks, tracking accuracy
  • TestProgressReader_LargeData - 10KB data with small buffer chunks
  • TestProgressReader_ZeroBytesRead - empty reader edge case
  • TestProgressReader_ConcurrentAccess - goroutine safety verification
  • TestImageFromGophercloud - full field mapping validation
  • TestImageFromGophercloud_Empty - zero-value struct
  • TestImageFromGophercloud_Queued/Private/Shared/CommunityVisibility - status and visibility coverage

Results

  • 23 test files (was 22)
  • 16 packages tested (was 15)
  • All tests passing, go test ./... clean

- cloud: Add CloudsYamlPaths tests, invalid/empty YAML, precedence verification
  (8 new tests covering path resolution, invalid YAML, detailed clouds.yaml parsing)
- config: Add edge case tests for empty/malformed files, partial configs,
  SaveTo directory creation, keybinding merging, round-trip verification
  (10 new tests covering validation, merge behavior, partial config handling)
- image: Add ProgressReader tests (concurrent access, large data, empty reader)
  and imageFromGophercloud conversion tests (empty, queued, visibility modes)
  (12 new tests)

Total: 30 new tests, all passing. Test file count: 22 → 23.
Packages tested expanded from 15 → 16 (added internal/image).
Copy link
Copy Markdown

Copilot AI left a comment

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 extends unit test coverage across the internal cloud, config, and image packages, adding a substantial number of new tests to validate parsing, defaults/merging behavior, and data mapping helpers.

Changes:

  • Added additional clouds.yaml path and parsing tests for cloud.ListCloudNames / cloud.CloudsYamlPaths.
  • Expanded config tests to cover empty/malformed files, partial merges, CLI-flag merges, and Save/Load round-trips.
  • Introduced first-time tests for image.ProgressReader and imageFromGophercloud field mapping.

Reviewed changes

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

File Description
src/internal/cloud/clouds_test.go Adds coverage for clouds.yaml search path ordering and additional ListCloudNames edge cases.
src/internal/config/config_test.go Adds coverage for config file parsing/merging behaviors and save/round-trip behavior.
src/internal/image/images_test.go Adds coverage for ProgressReader byte tracking and imageFromGophercloud mapping.

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

Comment on lines +133 to +146
func TestListCloudNames_InvalidYAML(t *testing.T) {
dir := t.TempDir()
content := `clouds:
bad:
[invalid yaml {{{
`
path := filepath.Join(dir, "clouds.yaml")
if err := os.WriteFile(path, []byte(content), 0644); err != nil {
t.Fatal(err)
}

t.Setenv("OS_CLIENT_CONFIG_FILE", path)

_, err := ListCloudNames()
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

These ListCloudNames tests can become flaky if the process working directory contains a real clouds.yaml (e.g., a developer has one in the repo root). ListCloudNames() searches clouds.yaml in the current directory before OS_CLIENT_CONFIG_FILE, so the test may read the wrong file. Consider os.Chdir(t.TempDir()) (and defer restore) like TestListCloudNames_NoFile does to isolate the current-directory lookup for this test (and similar ones below).

Copilot uses AI. Check for mistakes.
Comment on lines +159 to +164
func TestEmptyConfigFile(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "config.yaml")
os.WriteFile(path, []byte(""), 0o644)

loaded, err := LoadFrom(path)
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

os.WriteFile errors are ignored here. If the write fails, LoadFrom may fall back to defaults and this test could pass while silently not exercising the file-reading path. Please handle the returned error (and fail the test) to avoid false positives.

Copilot uses AI. Check for mistakes.
Comment on lines +246 to +252
// Verify content is valid YAML
data, err := os.ReadFile(path)
if err != nil {
t.Fatalf("Read file: %v", err)
}
if len(data) == 0 {
t.Error("file is empty")
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

The comment says this verifies the saved content is valid YAML, but the test only checks that the file is non-empty. Either unmarshal the bytes to confirm it parses as YAML (and ideally into the expected config struct), or adjust the comment to match what is actually being asserted.

Copilot uses AI. Check for mistakes.
@larkly larkly merged commit fe8fafb into main Apr 7, 2026
7 checks passed
@larkly larkly deleted the features/test-coverage-cloud-config-image branch April 7, 2026 19:45
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.

2 participants