Skip to content

test(time): cover Time.UnmarshalJSON error path (100% coverage) - #215

Merged
justinhwang merged 1 commit into
masterfrom
time-unmarshaljson-error-coverage
Sep 18, 2026
Merged

justinhwang merged 1 commit into
masterfrom
time-unmarshaljson-error-coverage

Conversation

@justinhwang

Copy link
Copy Markdown
Contributor

What

#208 added atomic.Time.MarshalJSON / UnmarshalJSON, but its TestTimeJSON only exercised valid JSON. The error branch of UnmarshalJSON (return err) was never executed:

func (x *Time) UnmarshalJSON(b []byte) error {
	var v time.Time
	if err := json.Unmarshal(b, &v); err != nil {
		return err   // <- never covered by #208's tests
	}
	x.Store(v)
	return nil
}

That dropped package coverage to 99.6%, below the 100% target in .codecov.yml.

Change

Adds an UnmarshalJSONError subtest to TestTimeJSON that feeds a well-formed JSON string which isn't a valid RFC 3339 timestamp. It asserts the decode error is propagated and that the wrapped value is left untouched.

Note: unlike the Duration/Bool/String error tests, this can't reuse the assertErrorJSONUnmarshalType helper — Time delegates to time.Time.UnmarshalJSON, which returns a *time.ParseError rather than a *json.UnmarshalTypeError.

Verification

  • go test -cover . → 100.0% of statements (was 99.6%)
  • make test (race suite) passes
  • gofmt -s and go vet ./... clean

Test-only change; no CHANGELOG entry (not user-facing).


Before opening your pull request, please make sure that you've:

  • updated the changelog if the change is user-facing; — n/a, test-only
  • added tests to cover your changes;
  • run the test suite locally (make test); and finally,
  • run the linters locally (make lint). — gofmt/go vet clean; golint install fails on this Go toolchain (pre-existing, unrelated)

🤖 Generated with Claude Code

#208 added atomic.Time.UnmarshalJSON but its test only exercised valid
input, so the error branch (`return err`) was never executed. That left
package coverage at 99.6%, below the 100% target in .codecov.yml.

Add an UnmarshalJSONError subtest that feeds a well-formed JSON string
which isn't a valid RFC 3339 timestamp, asserting the decode error is
propagated and the wrapped value is left untouched. Restores coverage
to 100%.

Signed-off-by: Justin Hwang <justinhwang@uber.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (786022a) to head (6275acd).

Additional details and impacted files
@@             Coverage Diff             @@
##           master      #215      +/-   ##
===========================================
+ Coverage   99.51%   100.00%   +0.48%     
===========================================
  Files          23        23              
  Lines         410       410              
===========================================
+ Hits          408       410       +2     
+ Misses          1         0       -1     
+ Partials        1         0       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@justinhwang
justinhwang enabled auto-merge (squash) September 17, 2026 21:46
@justinhwang
justinhwang merged commit 92fa5f6 into master Sep 18, 2026
11 checks passed
@justinhwang
justinhwang deleted the time-unmarshaljson-error-coverage branch September 18, 2026 08:40
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