Skip to content

Add integration tests#152

Open
chmeliik wants to merge 3 commits intokeilerkonzept:masterfrom
chmeliik:add-tests
Open

Add integration tests#152
chmeliik wants to merge 3 commits intokeilerkonzept:masterfrom
chmeliik:add-tests

Conversation

@chmeliik
Copy link
Contributor

@chmeliik chmeliik commented Oct 31, 2025

Over at https://github.com/konflux-ci/dockerfile-json, we've been continuing the the development of dockerfile-json (in the dev branch for now, hoping that we could get our fixes merged upstream as well)

To make that easier, we added a testing framework in konflux-ci#6. I think it would be valuable to have upstream as well, hence this PR :)

Note: most of the added lines are from adding go-cmp to the vendor directory

init() runs during package initialization, even when building test
binaries. This causes conflicts with the testing framework's flags
(e.g., -test.v, -test.paniconexit0).

By moving flag parsing to parseFlags() and calling it from main(),
flag.Parse() only runs when executing the binary, not during test
compilation. This unblocks adding tests for the main package.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Assisted-by: Claude <noreply@anthropic.com>
Signed-off-by: Adam Cmiel <acmiel@redhat.com>
Implements "snapshot testing" for dockerfile-json CLI output. Tests are
discovered from testdata/ directories containing a Containerfile. Use
UPDATE_TESTDATA=1 to regenerate the output files (expected.json).

Key design choices:
- Tests execute the actual binary
- Preserves deterministic key order from struct field serialization
- Simple directory structure makes adding tests trivial

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Assisted-by: Claude <noreply@anthropic.com>
Signed-off-by: Adam Cmiel <acmiel@redhat.com>
Replace simple JSON dump with go-cmp diff output for clearer test
failures. Shows only the differences instead of dumping both full JSONs.

Note: compares the JSONs as strings instead of unmarshalling and doing a
deep equality check on the objects. This results in more human-friendly
diffs. It works because the dockerfile-json output has deterministic
key order and because the tests preserve that key order by only using
json.Indent instead of doing Unmarshal->Marshal round tripping.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Assisted-by: Claude <noreply@anthropic.com>
Signed-off-by: Adam Cmiel <acmiel@redhat.com>
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.

1 participant