Skip to content

Add full feature-level coverage for Config contract in tests/feature#106

Merged
hwbrzzl merged 6 commits intomasterfrom
copilot/add-full-tests-config-module
Mar 14, 2026
Merged

Add full feature-level coverage for Config contract in tests/feature#106
hwbrzzl merged 6 commits intomasterfrom
copilot/add-full-tests-config-module

Conversation

Copy link

Copilot AI commented Mar 14, 2026

  • Identify actionable review comments and lint issue details
  • Reproduce lint/test failures locally for touched files
  • Apply minimal fixes to address comments and lint findings
  • Re-run targeted checks to verify fixes
  • Run final review + security checks and reply on PR comment
Original prompt

This section details on the original issue you should resolve

<issue_title>Add full tests for the Config module</issue_title>
<issue_description>### Before feedback (在反馈之前)

  • There are no features that I want to submit in Issues (当前 Issues 中没有我将要提交的新功能)

Describe Feature (描述功能)

Before feedback (在反馈之前)

  • There are no features that I want to submit in Issues (当前 Issues 中没有我将要提交的新功能)

Describe Feature (描述功能)

Before feedback (在反馈之前)

  • There are no features that I want to submit in Issues (当前 Issues 中没有我将要提交的新功能)

Describe Feature (描述功能)

We want to add integration tests for goravel/framework's features to ensure they work as expected.

  1. Add full tests for the Cache module in goravel/example based on the interface: https://github.com/goravel/framework/tree/master/contracts/config.
  2. The tests can be added in https://github.com/goravel/example/tree/master/tests/feature. Feel free to add a controller in https://github.com/goravel/example/tree/master/app/http/controllers if a request is required.
  3. Let tests fail if there are bugs in the module.
  4. Create a branch for the PR based on the master branch, and merge the PR to the master branch.</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Main features

Environment variable retrieval

  • Tests Env, EnvString, and EnvBool methods for reading environment variables with fallback defaults
  • Validates that missing environment variables return the provided default values

Configuration value management

  • Tests Add method to dynamically add configuration values at runtime
  • Tests Get, GetString, GetInt, GetBool, and GetDuration methods for type-safe retrieval with default fallbacks
  • Validates that missing configuration keys return the provided default values

Structured unmarshalling

  • Tests UnmarshalKey to map configuration entries into typed structs using mapstructure tags
  • Validates error handling when passing non-pointer types to UnmarshalKey (requires pointer argument)

Code examples

Environment variable retrieval:

s.T().Setenv("TESTS_CONFIG_ENV", "goravel")
s.Equal("goravel", facades.Config().Env("TESTS_CONFIG_ENV"))
s.Equal("default", facades.Config().Env("TESTS_CONFIG_ENV_MISSING", "default"))

Typed configuration retrieval:

facades.Config().Add("tests.config.int", 1)
s.Equal(1, facades.Config().GetInt("tests.config.int"))
s.Equal(2, facades.Config().GetInt("tests.config.int.missing", 2))

Structured unmarshalling:

facades.Config().Add("tests.config.unmarshal", map[string]any{
    "name":    "goravel",
    "enabled": true,
    "retries": 3,
})

type testConfig struct {
    Name    string `mapstructure:"name"`
    Enabled bool   `mapstructure:"enabled"`
    Retries int    `mapstructure:"retries"`
}

var config testConfig
err := facades.Config().UnmarshalKey("tests.config.unmarshal", &config)
s.Require().NoError(err)
s.Equal(testConfig{Name: "goravel", Enabled: true, Retries: 3}, config)

Error handling for invalid unmarshalling targets:

err = facades.Config().UnmarshalKey("tests.config.unmarshal", config)
s.Error(err)
s.ErrorContains(err, "pointer")

Copilot AI and others added 3 commits March 14, 2026 08:22
Co-authored-by: hwbrzzl <24771476+hwbrzzl@users.noreply.github.com>
Co-authored-by: hwbrzzl <24771476+hwbrzzl@users.noreply.github.com>
Co-authored-by: hwbrzzl <24771476+hwbrzzl@users.noreply.github.com>
Copilot AI changed the title [WIP] Add full tests for the Config module Add full feature-level coverage for Config contract in tests/feature Mar 14, 2026
Copilot AI requested a review from hwbrzzl March 14, 2026 08:29
@hwbrzzl
Copy link
Contributor

hwbrzzl commented Mar 14, 2026

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Mar 14, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3fb25a31-a6e4-402c-b096-980745bd4282

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This pull request adds a comprehensive test suite (ConfigTestSuite) in Go to validate the Config module's functionality through facade methods. The tests cover environment variable retrieval, configuration storage and retrieval with type conversion, and configuration unmarshaling into structs.

Changes

Cohort / File(s) Summary
Config Test Suite
tests/feature/config_test.go
New test suite with 10 test methods validating environment variables (Env, EnvString, EnvBool), configuration operations (Add, Get, GetString, GetInt, GetBool, GetDuration), and UnmarshalKey functionality including error cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding feature-level test coverage for the Config contract in tests/feature directory.
Linked Issues check ✅ Passed The PR fully implements the objective from issue #927: adds integration tests for Config module in tests/feature based on contracts/config interface, covering all interface methods with proper default handling and error cases.
Out of Scope Changes check ✅ Passed All changes are in-scope: the single new file tests/feature/config_test.go exclusively contains Config feature tests directly addressing issue #927 requirements with no unrelated modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch copilot/add-full-tests-config-module
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@hwbrzzl hwbrzzl marked this pull request as ready for review March 14, 2026 08:32
@hwbrzzl hwbrzzl requested a review from a team as a code owner March 14, 2026 08:32
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/feature/config_test.go (1)

34-39: Add false-path assertions for bool coverage completeness.

Current bool tests only validate truthy paths; include explicit false and default-false cases to catch one-sided regressions.

Proposed test additions
 func (s *ConfigTestSuite) TestEnvBool() {
 	s.T().Setenv("TESTS_CONFIG_ENV_BOOL", "true")
+	s.T().Setenv("TESTS_CONFIG_ENV_BOOL_FALSE", "false")

 	s.True(facades.Config().EnvBool("TESTS_CONFIG_ENV_BOOL"))
+	s.False(facades.Config().EnvBool("TESTS_CONFIG_ENV_BOOL_FALSE"))
 	s.True(facades.Config().EnvBool("TESTS_CONFIG_ENV_BOOL_MISSING", true))
+	s.False(facades.Config().EnvBool("TESTS_CONFIG_ENV_BOOL_MISSING_FALSE", false))
 }
@@
 func (s *ConfigTestSuite) TestGetBool() {
 	facades.Config().Add("tests.config.bool", true)
+	facades.Config().Add("tests.config.bool_false", false)

 	s.True(facades.Config().GetBool("tests.config.bool"))
+	s.False(facades.Config().GetBool("tests.config.bool_false"))
 	s.True(facades.Config().GetBool("tests.config.bool.missing", true))
+	s.False(facades.Config().GetBool("tests.config.bool.missing.false", false))
 }

Also applies to: 62-67

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/feature/config_test.go` around lines 34 - 39, Update the TestEnvBool
test to include false-path assertions: set an env var like
"TESTS_CONFIG_ENV_BOOL_FALSE" to "false" and assert
facades.Config().EnvBool("TESTS_CONFIG_ENV_BOOL_FALSE") is false, and add an
assertion for a missing key with an explicit default false (e.g.
facades.Config().EnvBool("TESTS_CONFIG_ENV_BOOL_MISSING_FALSE", false) ==
false). Do the same corresponding change for the other bool test referenced
(lines ~62-67) so both truthy and falsy/default-false cases are covered; locate
the checks via the TestEnvBool test function and calls to
facades.Config().EnvBool.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/feature/config_test.go`:
- Around line 12-18: The suite is missing the tests package bootstrap; add an
import for "goravel/tests" and embed tests.TestCase into the ConfigTestSuite
struct (or implement SetupSuite() to call tests.Boot() equivalents) so that
bootstrap.Boot() runs before tests; specifically update the ConfigTestSuite
definition (type ConfigTestSuite struct { suite.Suite }) to include
tests.TestCase and add the "goravel/tests" import to align with other feature
tests like orm_test.go/db_test.go/auth_test.go.

---

Nitpick comments:
In `@tests/feature/config_test.go`:
- Around line 34-39: Update the TestEnvBool test to include false-path
assertions: set an env var like "TESTS_CONFIG_ENV_BOOL_FALSE" to "false" and
assert facades.Config().EnvBool("TESTS_CONFIG_ENV_BOOL_FALSE") is false, and add
an assertion for a missing key with an explicit default false (e.g.
facades.Config().EnvBool("TESTS_CONFIG_ENV_BOOL_MISSING_FALSE", false) ==
false). Do the same corresponding change for the other bool test referenced
(lines ~62-67) so both truthy and falsy/default-false cases are covered; locate
the checks via the TestEnvBool test function and calls to
facades.Config().EnvBool.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a4d6789e-fda5-41da-be28-345ffcbb6b17

📥 Commits

Reviewing files that changed from the base of the PR and between b89d64e and 10b929f.

📒 Files selected for processing (1)
  • tests/feature/config_test.go

@hwbrzzl
Copy link
Contributor

hwbrzzl commented Mar 14, 2026

@copilot Fix the comments, and the file lint is incorrect, fix it as well.

Co-authored-by: hwbrzzl <24771476+hwbrzzl@users.noreply.github.com>
Copy link
Author

Copilot AI commented Mar 14, 2026

@copilot Fix the comments, and the file lint is incorrect, fix it as well.

Fixed in f19831c. I aligned tests/feature/config_test.go with the feature test pattern by importing goravel/tests and embedding tests.TestCase in ConfigTestSuite, and also corrected file formatting so lint is clean (gofmt). No UI changes in this PR, so there is no screenshot to provide.

@hwbrzzl hwbrzzl merged commit 7b7beca into master Mar 14, 2026
4 of 7 checks passed
@hwbrzzl hwbrzzl deleted the copilot/add-full-tests-config-module branch March 14, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants