btcdextresults_test.go raw
1 package btcjson_test
2
3 import (
4 "encoding/json"
5 "testing"
6
7 "github.com/p9c/p9/pkg/btcjson"
8 )
9
10 // TestPodExtCustomResults ensures any results that have custom marshalling work as intended and unmarshal code of
11 // results are as expected.
12 func TestPodExtCustomResults(t *testing.T) {
13 t.Parallel()
14 tests := []struct {
15 name string
16 result interface{}
17 expected string
18 }{
19 {
20 name: "versionresult",
21 result: &btcjson.VersionResult{
22 VersionString: "1.0.0",
23 Major: 1,
24 Minor: 0,
25 Patch: 0,
26 Prerelease: "pr",
27 BuildMetadata: "bm",
28 },
29 expected: `{"versionstring":"1.0.0","major":1,"minor":0,"patch":0,"prerelease":"pr","buildmetadata":"bm"}`,
30 },
31 }
32 t.Logf("Running %d tests", len(tests))
33 for i, test := range tests {
34 marshalled, e := json.Marshal(test.result)
35 if e != nil {
36 t.Errorf("Test #%d (%s) unexpected error: %v", i,
37 test.name, e,
38 )
39 continue
40 }
41 if string(marshalled) != test.expected {
42 t.Errorf("Test #%d (%s) unexpected marhsalled data - "+
43 "got %s, want %s", i, test.name, marshalled,
44 test.expected,
45 )
46 continue
47 }
48 }
49 }
50