Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test run outputs marshal/unmarshal #3574

Merged
merged 1 commit into from
Jan 29, 2024
Merged

Conversation

mathnogueira
Copy link
Contributor

This PR fixes a bug found in production that made the GetTestRun endpoint fail. It happened because the database had Error: {} as the value in the Outputs JSON.

Checklist

  • tested locally
  • added new dependencies
  • updated the docs
  • added a test

Loom video

Add your loom video here if your work can be visualized

Comment on lines +209 to +249
func TestRunOutput(t *testing.T) {
jsonContent := []byte(`[{"Key": "MY_OUTPUT", "Value": {"Name": "MY_OUTPUT", "Error": {}, "Value": "", "SpanID": "", "Resolved": false}}]`)

var output test.Run
err := json.Unmarshal(jsonContent, &output.Outputs)
require.NoError(t, err)
}

func TestRunOutputJSON(t *testing.T) {
jsonContent := []byte(`{"Name": "MY_OUTPUT", "Error": {}, "Value": "1", "SpanID": "2", "Resolved": true}`)

var output test.RunOutput
err := json.Unmarshal(jsonContent, &output)
require.NoError(t, err)

assert.Equal(t, "MY_OUTPUT", output.Name)
assert.Equal(t, "1", output.Value)
assert.Equal(t, "2", output.SpanID)
assert.Equal(t, true, output.Resolved)
assert.Nil(t, output.Error)
}

func TestRunOutputMarshalJSON(t *testing.T) {
var runOutput = test.RunOutput{
Name: "MY_OUTPUT",
Value: "1",
SpanID: "2",
Resolved: true,
Error: errors.New("not empty"),
}
jsonContent, _ := json.Marshal(runOutput)

var output test.RunOutput
err := json.Unmarshal(jsonContent, &output)
require.NoError(t, err)

assert.Equal(t, "MY_OUTPUT", output.Name)
assert.Equal(t, "1", output.Value)
assert.Equal(t, "2", output.SpanID)
assert.Equal(t, true, output.Resolved)
assert.Equal(t, "not empty", output.Error.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@schoren schoren merged commit 01ede97 into main Jan 29, 2024
37 checks passed
@schoren schoren deleted the fix/run-output-marshalling branch January 29, 2024 19:02
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