Skip to content

Add unit test for UnmarshalEmbeddedJSON helper in pkg/utils #6356

Description

@superplanehq-integration

Add one focused unit test.

  • Review the repository to find core logic and existing test patterns
  • Target a single untested helper or pure function in core logic
  • Use existing test tooling and patterns — do not add a new framework
  • Keep the change as small as possible
  • If there is no test tooling: add only the minimal setup for the primary language, just enough to run that one test

Problem

The helper UnmarshalEmbeddedJSON in pkg/utils/json.go is a small, pure-ish utility (it lazily unmarshals JSON bytes into a map[string]any guarded by a sync.Once) but it currently has no test coverage. Its sibling helper in the same package (NormalizeEmail) already has pkg/utils/email_test.go, so there is a clear, established pattern to follow without introducing anything new.

  • The project is Go (go 1.26.2, module github.com/superplanehq/superplane).
  • Existing tests use the standard testing package plus github.com/stretchr/testify/assert.
  • pkg/utils/email_test.go demonstrates the table-driven t.Run style used across the repo.
  • UnmarshalEmbeddedJSON(once *sync.Once, data []byte, target *map[string]any) map[string]any returns the populated map and caches it via once.Do.

Acceptance criteria

  • Add a single new test file pkg/utils/json_test.go in package utils.
  • Cover UnmarshalEmbeddedJSON with a table-driven test using testify/assert, matching the style of email_test.go.
  • Verify at least: valid JSON is parsed into the expected map, invalid/empty JSON yields an empty (non-nil) map, and the sync.Once caches the first result so a second call with different data returns the originally cached value.
  • Do not add any new test framework, dependency, or tooling.
  • Keep the change limited to the one new test file; do not modify json.go.
  • The test passes via go test ./pkg/utils/....

Automatically created by the Software Factory

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions