Skip to content

test(model): add unit tests for GetErrorMessage and Flag.MarshalJSON#1981

Open
anxkhn wants to merge 1 commit into
open-feature:mainfrom
anxkhn:loop/flagd__003
Open

test(model): add unit tests for GetErrorMessage and Flag.MarshalJSON#1981
anxkhn wants to merge 1 commit into
open-feature:mainfrom
anxkhn:loop/flagd__003

Conversation

@anxkhn

@anxkhn anxkhn commented Jun 30, 2026

Copy link
Copy Markdown

core/pkg/model had no test coverage (0.0%) even though it is imported by 17 packages and holds the core Flag type. This adds table-driven tests for the two functions in the package that have real behaviour:

  • GetErrorMessage: every known code maps to its readable message, and an unknown code falls through to Unknown error code: <code>.
  • Flag.MarshalJSON: locks in the non-obvious behaviour where key is deliberately omitted from the serialized JSON, FlagSetId/Priority (json:"-") never serialize, and targeting/metadata honour omitempty.

Test-only, no production change. Brings the package to 100% coverage.

Relates to #1773.

Checklist

  • Unit tests included (CONTRIBUTING requires it)
  • make test-core / go test -race -short ./pkg/model/ passes (100% cov)
  • make lint (golangci-lint v2.7.2) clean
  • DCO sign-off present, author == signoff
  • No markdown changes (markdownlint N/A)

core/pkg/model had no tests (0% coverage) despite being imported by 17
packages. Add table-driven tests covering both real functions:

- GetErrorMessage: every known code maps to its readable message and an
  unknown code falls through to "Unknown error code: <code>".
- Flag.MarshalJSON: locks in the non-obvious key omission and the
  json:"-" FlagSetId/Priority fields never serializing, plus the
  targeting/metadata omitempty behaviour.

Test-only; no production change. Brings the package to 100% coverage.

Relates to open-feature#1773

Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
@anxkhn anxkhn requested review from a team as code owners June 30, 2026 09:14
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Jun 30, 2026
@netlify

netlify Bot commented Jun 30, 2026

Copy link
Copy Markdown

Deploy Preview for polite-licorice-3db33c failed. Why did it fail? →

Name Link
🔨 Latest commit 75af3e6
🔍 Latest deploy log https://app.netlify.com/projects/polite-licorice-3db33c/deploys/6a438909294a7800081a235e

@netlify

netlify Bot commented Jun 30, 2026

Copy link
Copy Markdown

Deploy Preview for polite-licorice-3db33c ready!

Name Link
🔨 Latest commit 75af3e6
🔍 Latest deploy log https://app.netlify.com/projects/polite-licorice-3db33c/deploys/6a442f29b989acd918b3ec18
😎 Deploy Preview https://deploy-preview-1981--polite-licorice-3db33c.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3073c89d-dc13-4759-af5d-9248e72ab9f5

📥 Commits

Reviewing files that changed from the base of the PR and between d99a3e3 and 75af3e6.

📒 Files selected for processing (1)
  • core/pkg/model/model_test.go

📝 Walkthrough

Walkthrough

Adds core/pkg/model/model_test.go with unit tests covering GetErrorMessage error-code-to-string mapping and Flag JSON marshaling, verifying field inclusion/exclusion behavior.

Changes

Model Unit Tests

Layer / File(s) Summary
GetErrorMessage and Flag JSON marshaling tests
core/pkg/model/model_test.go
Tests verify GetErrorMessage returns expected strings for known, unknown, and empty error codes; Flag JSON output omits key, FlagSetId, and Priority while including state, defaultVariant, source, variants, targeting, and metadata; a separate test confirms optional fields are omitted when empty.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 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
Title check ✅ Passed The title accurately summarizes the main change: adding unit tests for GetErrorMessage and Flag.MarshalJSON.
Description check ✅ Passed The description is directly related to the change and matches the added test coverage for core/pkg/model.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant