Skip to content

Commit

Permalink
Missing tests for JSON/XML outputs (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe authored Jan 29, 2023
1 parent cf3cdaa commit 988ce7a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .snapshots/TestMarshalErrorXMLPageResult
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<xmlPageResult name="http://foo.com" tests="1" failures="1" skipped="0">
<testcase name="http://foo.com/bar" classname="http://foo.com">
<failure message="baz"></failure>
</testcase>
</xmlPageResult>
2 changes: 1 addition & 1 deletion .snapshots/TestMarshalSuccessJSONPageResult
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"url":"http://foo.com","links":[{"url":"http://foo.com/foo","status":200}]}
{"url":"http://foo.com","links":[]}
3 changes: 3 additions & 0 deletions .snapshots/TestMarshalSuccessXMLPageResult
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<xmlPageResult name="http://foo.com" tests="1" failures="0" skipped="0">
<testcase name="http://foo.com/bar" classname="http://foo.com"></testcase>
</xmlPageResult>
1 change: 1 addition & 0 deletions .snapshots/TestMarshalVerboseSuccessJSONPageResult
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"url":"http://foo.com","links":[{"url":"http://foo.com/foo","status":200}]}
13 changes: 13 additions & 0 deletions json_page_result_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ func TestMarshalErrorJSONPageResult(t *testing.T) {
}

func TestMarshalSuccessJSONPageResult(t *testing.T) {
bs, err := json.Marshal(newJSONPageResult(
&pageResult{
"http://foo.com",
[]*successLinkResult{
{"http://foo.com/foo", 200},
},
[]*errorLinkResult{},
}, false))
assert.Nil(t, err)
cupaloy.SnapshotT(t, bs)
}

func TestMarshalVerboseSuccessJSONPageResult(t *testing.T) {
bs, err := json.Marshal(newJSONPageResult(
&pageResult{
"http://foo.com",
Expand Down
40 changes: 40 additions & 0 deletions xml_page_result_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"encoding/xml"
"errors"
"testing"

"github.com/bradleyjkemp/cupaloy"
"github.com/stretchr/testify/assert"
)

func TestMarshalErrorXMLPageResult(t *testing.T) {
bs, err := marshalXML(newXMLPageResult(
&pageResult{
"http://foo.com",
[]*successLinkResult{},
[]*errorLinkResult{
{"http://foo.com/bar", errors.New("baz")},
},
}))
assert.Nil(t, err)
cupaloy.SnapshotT(t, bs)
}

func TestMarshalSuccessXMLPageResult(t *testing.T) {
bs, err := marshalXML(newXMLPageResult(
&pageResult{
"http://foo.com",
[]*successLinkResult{
{"http://foo.com/bar", 200},
},
[]*errorLinkResult{},
}))
assert.Nil(t, err)
cupaloy.SnapshotT(t, bs)
}

func marshalXML(x any) ([]byte, error) {
return xml.MarshalIndent(x, "", " ")
}

0 comments on commit 988ce7a

Please sign in to comment.