Merged
Conversation
## 変更内容 - 失敗していたテスト修正: 環境変数PORTのクリア処理追加 - internal/errors: テストカバレッジ 0% -> 46.2% - internal/logger: テストカバレッジ 0% -> 51.4% - internal/config: テストカバレッジ 0% -> 75.0% - cmd: テストカバレッジ 9.2% -> 28.0% ## 修正詳細 ### 1. yaml_test.go (環境変数バグ修正) - PORT環境変数が設定されていたため、デフォルト値のテストが失敗 - テスト実行前に環境変数をクリアする処理を追加 ### 2. 新規テストファイル追加 - internal/errors/codes_test.go: ErrorCodeのテスト - internal/errors/types_test.go: AppErrorの各メソッドテスト - internal/logger/structured_test.go: StructuredLoggerのテスト - internal/config/default_test.go: 設定関連のテスト ## テスト結果 全テストがパス。主要モジュールのカバレッジが大幅に向上。 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Fix existing test failure in yaml_test.go (environment variable issue) - Add internal/config tests (100% coverage achieved) - Add internal/scanner/validator tests (port validation) - Improve overall test coverage from 13.7% to 45.6% Test statistics: - New test files: 2 - Total test coverage improvement: 3.3x - All tests: PASS Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Implement comprehensive tests for internal/scanner/network.go - Coverage: NewDockerNetworkDetector 100%, DetectNetworks 88.9% - Test cases: - Constructor validation - Network detection integration test - Context cancellation handling - NetworkInfo data structure validation - Edge cases and boundary conditions - Achieves 88.9% coverage (target: 60%) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add comprehensive test cases for ParseServicePorts - Add tests for parsePortObject (object-format ports) - Add tests for parseEnvironment (array/map formats) - Add tests for parseDependsOn (array/map formats) - Add tests for parseNetworks (simple/detailed configs) - Add tests for convertToNetwork (empty/no-ipam/multi-subnet) - Add edge case tests with real YAML files - Add error handling tests for invalid port formats Test data files: - testdata/parser/edge_cases.yml: comprehensive edge cases - testdata/parser/invalid.yml: invalid format tests Coverage improved: 14.1% → 72.5% Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- errcheck: WithField の戻り値を変数に代入 - staticcheck SA5011: t.Error を t.Fatal に変更し nil ポインタ参照を防止 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- override_test.go: カスタムcontains関数をstrings.Containsに置換 - unified_generator_test.go: string(rune(i))をfmt.Sprintfに修正 - network_test.go: nil contextテスト名と実装を一致させる - structured_test.go: FormatJSONテストに出力内容検証を追加 - testutil/mocks.go: 共通モックをtestutilパッケージに集約 - conflict_test.go: 未使用変数を削除、共通モック使用に移行 - yaml_test.go: 環境変数クリーンアップ改善、invalid.ymlテスト追加 - テスト名を英語に統一 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Translate all Japanese test names and comments to English across all test files - Replace Reserved array loop comparison with reflect.DeepEqual in config/default_test.go - Remove duplicate boundary test cases from TestValidatePort (consolidated in TestValidatePortEdgeCases) - Strengthen TestAllocateNewSubnet validation (t.Logf -> t.Errorf for strict assertion) - Fix misleading env cleanup comments in yaml_test.go Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Translate Japanese comments to English in testdata and testutil - Add NewTestLogger helper to reduce boilerplate across tests - Verify slog.Level values in TestParseLogLevel - Use t.Skip for Docker-dependent integration tests - Replace fragile string comparison with checkServiceIPs field - Restructure invalid.yml for clearer test intent Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Replace test boilerplate with testutil.NewTestLogger() across 8 files (-67 lines) - Replace time.Now() with fixed time in override_test.go for reproducibility - Add pointer comparison clarifying comment in default_test.go - Add backward compatibility comment for port regex in yaml.go - Add minimum network count assertion in network_test.go Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
IsZero() check is sufficient to verify GeneratedAt is set. time.Since() with 1-second threshold could fail in slow CI environments. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
config, errors, generator, logger, parser, resolver, scanner
の各パッケージに対して包括的なユニットテストを追加し、プロジェクト全体のテストカバレッジを大幅に向上させる。テストユーティリティ (
testutil)の導入により、テストコードのボイラープレートも削減した。
変更内容
internal/testutil/mocks.goを新規追加し、NewTestLogger()/MockPortDetector/MockPortAllocatorを共通化internal/config/default_test.goを追加 — デフォルト設定・環境別設定・設定インスタンスの独立性テストinternal/errors/codes_test.go,types_test.goを追加 — エラーコード分類・AppError のチェーンテストinternal/generator/override_test.go,unified_generator_test.goを追加 — オーバーライド生成・バリデーション・YAML出力テストinternal/logger/structured_test.goを追加 — ログファクトリ・レベル解析・フォーマットテストinternal/parser/yaml_test.goを拡張 — ポート解析・環境変数・depends_on・ネットワーク・エッジケーステストinternal/resolver/conflict_test.goを追加 — コンフリクト検出・解決・分析・最適化テストinternal/scanner/network_test.go,unified_detector_test.go,validator_test.goを追加 — ネットワーク検出・統合検出・ポートバリデーションテストinternal/scanner/port_allocator_test.goを拡張 — 予約ポートスキップの網羅テストcmd/up_test.goのテスト名を英語に統一internal/parser/yaml.goのポート正規表現に後方互換性コメントを追加testdata/parser/edge_cases.yml,invalid.ymlをテストデータとして追加期待すること
testutilによりテストコードの保守性・一貫性が向上する動作確認
go test ./...全パッケージ通過golangci-lint run ./...0 issuesgo build ./...ビルド成功t.Skipでスキップされるtestdata/parser/edge_cases.yml) のパースが正常に完了するtestdata/parser/invalid.yml) でエラーが返されるabc:80形式でパースエラー