-
Notifications
You must be signed in to change notification settings - Fork 0
/
cv_test.go
49 lines (42 loc) · 1.3 KB
/
cv_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
package main
import (
"encoding/json"
"fmt"
"strings"
"testing"
)
func checkErr(err error) {
if err != nil {
panic(err.Error())
}
}
func mustEq(a string, b string) {
if a != b {
panic(fmt.Sprintf("left != right : %s != %s", a, b))
}
}
func TestStrippedCVWithOriginal(t *testing.T) {
testInput := []byte(`{"referenceNumber":"a","other":true,"personalDetails":{"zip":"1234"}}`)
testOutput := StrippedCVWithOriginal{}
err := json.Unmarshal(testInput, &testOutput)
checkErr(err)
mustEq("a", testOutput.ReferenceNumber)
mustEq("1234", testOutput.PersonalDetails.Zip)
formattedOutput, err := json.Marshal(testOutput)
checkErr(err)
mustEq(string(testInput), string(formattedOutput))
testInput = []byte(strings.Join([]string{`[`,
`{"referenceNumber":"a","other1":true,"personalDetails":{"zip":"1234"}},`,
`{"referenceNumber":"b","personalDetails":{"zip":"4321","other2":true}}`,
`]`}, ""))
testOutputs := []StrippedCVWithOriginal{}
err = json.Unmarshal(testInput, &testOutputs)
checkErr(err)
mustEq("a", testOutputs[0].ReferenceNumber)
mustEq("1234", testOutputs[0].PersonalDetails.Zip)
mustEq("b", testOutputs[1].ReferenceNumber)
mustEq("4321", testOutputs[1].PersonalDetails.Zip)
formattedOutput, err = json.Marshal(testOutputs)
checkErr(err)
mustEq(string(testInput), string(formattedOutput))
}