Skip to content

test: improve gitvolume package coverage#29

Merged
laggu merged 4 commits intodevelopfrom
gv-029
Feb 20, 2026
Merged

test: improve gitvolume package coverage#29
laggu merged 4 commits intodevelopfrom
gv-029

Conversation

@laggu
Copy link
Owner

@laggu laggu commented Feb 19, 2026

Summary

Improve internal/gitvolume package test coverage from 62.9% → 80.0%.

Changes

New Test Files

  • fs_test.go: copyFile, copyDir, hashFile, hashDir, cleanEmptyParents
  • remove_test.go: GlobalRemove, beforeAllRemove, beforeRemove, remove, afterRemove
  • git_test.go: FindWorktreeRoot, findCommonDir, isBareRepository
  • init_test.go: Init, beforeInit, init, afterInit (quiet/non-quiet/error)

Enhanced Existing Tests

  • sync_test.go: symlink rejection, path traversal, verbose, non-quiet error
  • unsync_test.go: type mismatch (source dir vs target file)
  • context_test.go: empty config, CheckStatus (9 subtests)
  • list_test.go: GlobalList, printNode
  • status_test.go: afterAllStatus
  • gitvolume_test.go: accessor methods, validatePath .git blocking

Bug Fix

  • git_repro_test.go: removed redundant git init --bare causing git clone --bare failure

Verification

ok  github.com/laggu/git-volume/internal/gitvolume  coverage: 80.0% of statements

Closes #29

- Add fs_test.go: copyFile, copyDir, hashFile, hashDir, cleanEmptyParents
- Add remove_test.go: GlobalRemove, beforeAllRemove, beforeRemove, remove, afterRemove
- Add git_test.go: FindWorktreeRoot, findCommonDir, isBareRepository
- Add init_test.go: Init, beforeInit, init, afterInit (quiet/non-quiet/error)
- Enhance sync_test.go: symlink rejection, path traversal, verbose, non-quiet error
- Enhance unsync_test.go: type mismatch (source dir vs target file)
- Enhance context_test.go: empty config, CheckStatus (9 subtests)
- Enhance list_test.go: GlobalList, printNode
- Enhance status_test.go: afterAllStatus
- Enhance gitvolume_test.go: accessor methods, validatePath .git blocking
- Fix git_repro_test.go: remove redundant git init --bare causing clone failure

Closes #29
@gemini-code-assist
Copy link

Summary of Changes

Hello @laggu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on bolstering the robustness of the internal/gitvolume package by substantially increasing its test coverage. It introduces comprehensive test cases for various utilities, ensuring reliable file system interactions, correct Git repository identification, and proper initialization behavior. The enhancements also fortify existing functionalities against potential issues like security vulnerabilities and unexpected data states, contributing to a more stable and predictable system.

Highlights

  • Increased Test Coverage: The pull request significantly improves the test coverage of the internal/gitvolume package, raising it from 62.9% to 80.0%.
  • New Test Suites: New test files were introduced for core functionalities including file system operations (fs_test.go), global removal (remove_test.go), Git repository detection (git_test.go), and initialization (init_test.go).
  • Enhanced Existing Tests: Existing test suites for sync, unsync, context, list, status, and gitvolume were expanded to cover more edge cases, such as symlink rejection, path traversal, verbose output, and type mismatches.
  • Bug Fix: A bug in git_repro_test.go was fixed, addressing a redundant git init --bare command that caused git clone --bare failures.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • internal/gitvolume/context_test.go
    • Added tests for handling empty configuration files.
    • Expanded CheckStatus tests to cover various linking and copying scenarios, including missing sources and modified files.
  • internal/gitvolume/debug_find_common_dir_test.go
    • Added a new test file to thoroughly verify the findCommonDir function's behavior with regular and bare Git repositories, including worktrees.
  • internal/gitvolume/fs_test.go
    • Added tests for copyFile covering normal copy, missing source, and read-only destinations.
    • Added tests for copyDir including normal recursive copy, symlinks in source, and target existence checks.
    • Added tests for hashFile and verifyHash functions.
    • Added tests for cleanEmptyParents logic, ensuring correct directory removal and stopping at non-empty parents.
  • internal/gitvolume/git_repro_test.go
    • Added a new test file to reproduce and validate findCommonDir behavior in complex Git repository setups involving bare repositories and worktrees.
  • internal/gitvolume/git_test.go
    • Added tests for FindWorktreeRoot from both repository root and subdirectories.
    • Added tests for findCommonDir in regular repositories.
    • Added tests for isBareRepository for both regular and bare Git repositories.
  • internal/gitvolume/gitvolume_test.go
    • Added tests for GitVolume accessor methods (SourceDir, TargetDir, GlobalDir, Context, HasGlobalVolumes).
    • Added tests for validatePath to ensure .git directories are blocked.
  • internal/gitvolume/init_test.go
    • Added tests for the Init function covering successful initialization, idempotency, and behavior outside a Git repository.
    • Added tests for Init with non-quiet output and error scenarios.
  • internal/gitvolume/list_test.go
    • Added tests for GlobalList functionality, including scenarios with empty global directories, uninitialized global storage, and nested directories.
    • Added tests for the printNode utility function.
  • internal/gitvolume/remove_test.go
    • Added tests for GlobalRemove covering successful removal of files and directories, handling missing files, path traversal prevention, and aggregation of multiple errors.
    • Added a test for GlobalRemove when global storage is not initialized.
  • internal/gitvolume/status_test.go
    • Added a test for the afterAllStatus function, covering both success and error cases.
  • internal/gitvolume/sync_test.go
    • Added tests for Sync to reject symlinks as sources.
    • Added tests for Sync to prevent path traversal vulnerabilities in both source and target paths.
    • Added tests for Sync with verbose output.
    • Added a test for Sync handling non-quiet error reporting.
  • internal/gitvolume/unsync_test.go
    • Added a test for Unsync to correctly handle type mismatches between source directories and target files, ensuring safety checks prevent unintended removals.
Activity
  • The author laggu initiated this pull request to address test coverage deficiencies in the internal/gitvolume package.
  • New test files were created to cover previously untested functions and scenarios.
  • Existing test files were updated with additional test cases to improve their comprehensiveness.
  • A specific bug related to Git repository initialization in a test was identified and fixed.
  • The pull request aims to achieve an 80.0% test coverage target for the package.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

이 PR은 gitvolume 패키지의 테스트 커버리지를 62.9%에서 80.0%로 크게 향상시키는 훌륭한 기여입니다. 파일 시스템 연산, git 상호작용, 명령어 로직에 대한 다양한 엣지 케이스를 다루는 다수의 새 테스트 파일이 추가되어 프로젝트의 안정성을 크게 높였습니다. 특히 경로 탐색 및 심볼릭 링크 처리와 같은 보안 측면에 대한 테스트가 추가된 점이 매우 가치 있습니다.

테스트 코드의 에러 처리와 관련하여 프로젝트 스타일 가이드를 위반하는 몇 가지 사소한 개선점을 발견했습니다. 자세한 내용은 개별 코멘트를 참고해주세요. 이 부분들이 수정되면 PR이 더욱 완성도 높아질 것입니다.

@laggu laggu changed the title test: improve gitvolume package coverage from 62.9% to 80% (#29) test: improve gitvolume package coverage from 62.9% to 80% Feb 19, 2026
@laggu laggu changed the title test: improve gitvolume package coverage from 62.9% to 80% test: improve gitvolume package coverage Feb 20, 2026
- context_test.go: check os.Getwd() error in TestNewWorkspace_EmptyConfig
- debug_find_common_dir_test.go: check cmd.Output() error with t.Logf
- git_test.go: check filepath.EvalSymlinks() errors with require.NoError
@laggu
Copy link
Owner Author

laggu commented Feb 20, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

이 PR은 internal/gitvolume 패키지의 테스트 커버리지를 62.9%에서 80.0%로 크게 향상시켰습니다. 새로운 테스트 파일들이 추가되고 기존 테스트들이 개선되어 코드의 안정성이 높아졌습니다. 전반적으로 훌륭한 기여입니다.

다만, 몇 가지 개선점을 제안합니다. context_test.goTestCheckStatus 함수는 프로젝트 스타일 가이드에 따라 테이블 기반 테스트로 리팩토링하면 더 간결하고 유지보수하기 좋아질 것입니다. 또한, debug_find_common_dir_test.go 파일은 git_repro_test.go와 내용이 중복되므로, 디버깅용 코드를 정리하고 파일을 제거하는 것을 고려해볼 수 있습니다. 자세한 내용은 각 파일에 남긴 주석을 참고해주세요.

…bug test

- context_test.go: refactor TestCheckStatus to table-driven test pattern
- debug_find_common_dir_test.go: remove duplicate debug test file
  (covered by git_repro_test.go)
@laggu
Copy link
Owner Author

laggu commented Feb 20, 2026

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request significantly improves test coverage for the gitvolume package, increasing it from 62.9% to 80.0%. It introduces comprehensive tests for file system operations, git integration (including worktrees and bare repositories), and core logic such as sync/unsync and status checks. The use of table-driven tests and proper cleanup in most places is excellent. I have suggested a few improvements for test robustness and consistency, specifically regarding the use of t.TempDir() and checking for the git binary in integration tests.

Comment on lines +15 to +17
tmpDir, err := os.MkdirTemp("", "git-volume-repro-*")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)

Choose a reason for hiding this comment

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

medium

For modern Go tests (1.15+), it is recommended to use t.TempDir() instead of os.MkdirTemp. t.TempDir() automatically handles directory creation and cleanup, and ensures a unique directory for each test. Additionally, since this is an integration test that relies heavily on the git binary, it's good practice to check for its availability and skip the test if it's missing, preventing unnecessary failures in environments without git.

Suggested change
tmpDir, err := os.MkdirTemp("", "git-volume-repro-*")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)
if _, err := exec.LookPath("git"); err != nil {
t.Skip("git command not found, skipping integration test")
}
tmpDir := t.TempDir()
References
  1. The project follows standard Go conventions. Using t.TempDir() is the idiomatic way to manage temporary directories in tests. (link)

}

// Resolve symlinks for accurate comparison
bareRepo, err = filepath.EvalSymlinks(bareRepo)

Choose a reason for hiding this comment

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

medium

Since err is no longer declared at the start of the function (if using the suggested t.TempDir() change), it should be declared here using the short variable declaration operator :=.

Suggested change
bareRepo, err = filepath.EvalSymlinks(bareRepo)
bareRepo, err := filepath.EvalSymlinks(bareRepo)

}

// Resolve symlinks
mainRepo, err = filepath.EvalSymlinks(mainRepo)

Choose a reason for hiding this comment

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

medium

Since err is no longer declared at the start of the function (if using the suggested t.TempDir() change), it should be declared here using the short variable declaration operator :=.

Suggested change
mainRepo, err = filepath.EvalSymlinks(mainRepo)
mainRepo, err := filepath.EvalSymlinks(mainRepo)

Comment on lines +62 to +64
tmpDir, err := os.MkdirTemp("", "git-volume-test")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)

Choose a reason for hiding this comment

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

medium

Use t.TempDir() for automatic temporary directory management and cleanup, consistent with other tests in this package.

Suggested change
tmpDir, err := os.MkdirTemp("", "git-volume-test")
require.NoError(t, err)
defer os.RemoveAll(tmpDir)
tmpDir := t.TempDir()
References
  1. The project follows standard Go conventions. Using t.TempDir() is the idiomatic way to manage temporary directories in tests. (link)

@laggu laggu merged commit 0d7d504 into develop Feb 20, 2026
6 checks passed
@laggu laggu deleted the gv-029 branch February 20, 2026 04:35
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

Comments