forked from fhirbase/fhirbase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transform_test.go
106 lines (94 loc) · 2.62 KB
/
transform_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"fmt"
"testing"
"github.com/google/go-cmp/cmp"
jsoniter "github.com/json-iterator/go"
)
func parseJson(str string) map[string]interface{} {
iter := jsoniter.ConfigFastest.BorrowIterator([]byte(str))
defer jsoniter.ConfigFastest.ReturnIterator(iter)
return iter.Read().(map[string]interface{})
}
func encodeJson(m map[string]interface{}) string {
stream := jsoniter.ConfigFastest.BorrowStream(nil)
defer jsoniter.ConfigFastest.ReturnStream(stream)
stream.WriteVal(m)
return string(stream.Buffer())
}
var cases = [][]string{
[]string{
`
{
"resourceType":"CarePlan",
"careTeam": [
{"reference": "Practitioner/1", "display": "John"},
{"reference": "Practitioner/2", "display": "Ian"}
],
"identifier": [
{"system": "foo", "value": "bar"},
{"system": "foo", "value": "baz", "assigner": { "reference": "Practitioner/42", "display": "John Doe"}}
]}`,
`{
"resourceType":"CarePlan",
"careTeam":[
{"id":"1","resourceType":"Practitioner","display":"John"},
{"id":"2","resourceType":"Practitioner","display":"Ian"}
],
"identifier":[
{"system":"foo","value":"bar"},
{"system":"foo","value":"baz","assigner":{"id":"42","resourceType":"Practitioner","display":"John Doe"}}
]}`,
},
[]string{
`
{
"resourceType":"Claim",
"information": [
{"valueReference": {"reference": "Immunization/123"}}
]}`,
`{
"resourceType":"Claim",
"information": [
{"value": {"Reference": { "resourceType": "Immunization", "id": "123" }}}
]}`,
},
[]string{
`{
"resourceType":"Patient",
"name": [{"given": ["Mike"], "family": "Lapshin"}],
"deceasedBoolean": true,
"multipleBirthInteger": 2,
"managingOrganization": { "reference": "Organization/1", "display": "ACME corp"}
}`, `{
"managingOrganization":{"id":"1","resourceType":"Organization","display":"ACME corp"},
"resourceType":"Patient",
"deceased": { "boolean": true },
"multipleBirth": { "integer": 2 },
"name":[{"family":"Lapshin","given":["Mike"]}],
}`,
}, []string{
`{"resourceType":"Patient", "managingOrganization": { "display": "ACME corp"}}`,
`{"resourceType":"Patient", "managingOrganization":{"display":"ACME corp"}}`,
},
[]string{
`{"resourceType":"FoobarUnknown", "foo": 42}`,
`{"resourceType":"FoobarUnknown", "foo": 42}`,
},
}
func TestTransform(t *testing.T) {
for i, c := range cases {
t.Run(fmt.Sprintf("Transform case #%d", i), func(t *testing.T) {
in := parseJson(c[0])
out := parseJson(c[1])
result, err := doTransform(in, "3.0.1")
if err != nil {
t.Error(err)
}
if !cmp.Equal(out, result) {
t.Logf("Expected:\n%v\nGot:\n%v\nDifference:\n%v", out, result, cmp.Diff(result, out))
t.Fail()
}
})
}
}