...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package bzltestutil
16
17 import (
18 "bytes"
19 "io/ioutil"
20 "os"
21 "path/filepath"
22 "strings"
23 "testing"
24 )
25
26 func TestJSON2XML(t *testing.T) {
27 files, err := filepath.Glob("testdata/*.json")
28 if err != nil {
29 t.Fatal(err)
30 }
31
32 for _, file := range files {
33 name := strings.TrimSuffix(filepath.Base(file), ".json")
34 t.Run(name, func(t *testing.T) {
35 orig, err := os.Open(file)
36 if err != nil {
37 t.Fatal(err)
38 }
39 got, err := json2xml(orig, "pkg/testing")
40 if err != nil {
41 t.Fatal(err)
42 }
43
44 target := strings.TrimSuffix(file, ".json") + ".xml"
45 want, err := ioutil.ReadFile(target)
46 if err != nil {
47 t.Fatal(err)
48 }
49
50 if !bytes.Equal(got, want) {
51 t.Errorf("json2xml for %s does not match, got:\n%s\nwant:\n%s\n", name, string(got), string(want))
52 }
53 })
54 }
55 }
56
View as plain text