Skip to content

Conversation

@jmcarp
Copy link
Contributor

@jmcarp jmcarp commented Jan 14, 2026

It's easy to make changes to the code generation logic that generate sdk code that appears to be correct and passes unit tests, but doesn't interact correctly with nexus. This patch introduces the concept of golden tests for nexus endpoints: we fetch real responses from a few endpoints of interest, check in the resulting json, and assert that we can unmarshal it into our generated types and marshal it back to equivalent json correctly. We also include a script and make target for refreshing golden files.

@jmcarp jmcarp requested a review from a team as a code owner January 14, 2026 16:22
Copy link
Member

@lgfa29 lgfa29 left a comment

Choose a reason for hiding this comment

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

This looks great!

// To refresh the fixtures, run:
//
// go run ./oxide/testdata/record/main.go
func TestGoldenRoundTrip(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

"The Golden Round Trip" sounds like a cool movie 😄

Comment on lines 61 to 78
// timestampComparer returns a cmp.Option that compares timestamp strings
// by their actual time value, handling precision differences. Rust and go format timestamps slightly differently, so we need to normalize to avoid spurious differences in marshalled values.
Copy link
Member

Choose a reason for hiding this comment

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

Minor nit, but the different line length in the comments looks a bit weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this was annoying me, so I'm proposing a linter/formatter change in #363. I'll fix here as well.

}

// doRequest makes a request to the configured nexus instance. We use the standard library here and not our own sdk because we're generating test files to verify the generated code.
func doRequest(method, url, token, body string) ([]byte, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should send the API version in the request to make sure we're testing the same structure? For example, if I update the golden files pointing to server that has an older released, the tests will probably fail in a (possibly) confusing way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to make this optional for now by adding a flag to the record command. Maybe I'm thinking about this wrong, but I think if VERSION_OMICRON is ahead of our test rack (in this case I used dogfood), we can't record responses. I think we can change this later if it causes problems.

Copy link
Member

Choose a reason for hiding this comment

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

Another minor nit, but it may be better to keep these files in a separate directory. I think we'll start collecting a bunch of them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I moved these around into their own directory.

@jmcarp jmcarp force-pushed the jmcarp/golden-tests branch from 2dc317c to 0b40072 Compare January 14, 2026 19:13
It's easy to make changes to the code generation logic that generate sdk code
that appears to be correct and passes unit tests, but doesn't interact
correctly with nexus. This patch introduces the concept of golden tests for
nexus endpoints: we fetch real responses from a few endpoints of interest,
check in the resulting json, and assert that we can unmarshal it into our
generated types and marshal it back to equivalent json correctly. We also
include a script and make target for refreshing golden files.
@jmcarp jmcarp force-pushed the jmcarp/golden-tests branch from 0b40072 to 8151648 Compare January 14, 2026 19:43
@jmcarp jmcarp merged commit 2f67dbc into main Jan 15, 2026
2 checks passed
@jmcarp jmcarp deleted the jmcarp/golden-tests branch January 15, 2026 16:45
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.

3 participants