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: run output unmarshal #2882

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions server/test/test_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,28 @@ func (o *Outputs) UnmarshalJSON(data []byte) error {
return fmt.Errorf("test output json version is not supported. Expecting version 1 or 2")
}

func (output *RunOutput) UnmarshalJSON(data []byte) error {
obj := struct {
Name string
Value string
SpanID string
Resolved bool
Error string
}{}

err := json.Unmarshal(data, &obj)
if err != nil {
return err
}

output.Name = obj.Name
output.Value = obj.Value
output.SpanID = obj.SpanID
output.Resolved = obj.Resolved
output.Error = fmt.Errorf(obj.Error)
return nil
}

func (sar SpanAssertionResult) MarshalJSON() ([]byte, error) {
sid := ""
if sar.SpanID != nil {
Expand Down
21 changes: 21 additions & 0 deletions server/test/test_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,27 @@ func TestOutputsV1(t *testing.T) {
assert.Equal(t, `attr:user_name`, testObject.Outputs[1].Value)
}

func TestXXX(t *testing.T) {
jsonData := `[
{
"Key": "http.host",
"Value": {
"Name": "http.host",
"Error": "",
"Value": "demo-pokemon-api.demo.svc.cluster.local",
"SpanID": "e28a7819ce8e0a01",
"Resolved": true
}
}
]`

run := test.Run{}
err := json.Unmarshal([]byte(jsonData), &run.Outputs)

require.NoError(t, err)
assert.Equal(t, run.Outputs.Len(), 1)
}

func TestOutputsV2(t *testing.T) {
v2Format := make([]test.Output, 0)
v2Format = append(v2Format, test.Output{
Expand Down