-
Notifications
You must be signed in to change notification settings - Fork 35
/
main_test.go
85 lines (77 loc) · 1.95 KB
/
main_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
// Copyright ©2019 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main // import "go-hep.org/x/hep/cmd/arrow2root"
import (
"os"
"path/filepath"
"strings"
"testing"
"go-hep.org/x/hep/groot/rcmd"
)
func TestConvert(t *testing.T) {
tmp, err := os.MkdirTemp("", "arrow2root-")
if err != nil {
t.Fatalf("could not create tmpdir: %+v", err)
}
defer os.RemoveAll(tmp)
for _, tc := range []struct {
name string
panics string
}{
{
name: "testdata/primitives.file.data",
},
{
name: "testdata/arrays.file.data",
},
{
name: "testdata/strings.file.data",
},
{
name: "testdata/fixed_size_binaries.file.data",
},
{
name: "testdata/lists.file.data",
},
{
name: "testdata/structs.file.data",
panics: "invalid ARROW data-type: *arrow.StructType", // FIXME(sbinet): needs non-flat-tree writer support
},
} {
t.Run(tc.name, func(t *testing.T) {
if tc.panics != "" {
defer func() {
err := recover()
if err == nil {
t.Fatalf("expected a panic (%s)", tc.panics)
}
if got, want := err.(error).Error(), tc.panics; got != want {
t.Fatalf("invalid panic message:\ngot= %v\nwant=%v", got, want)
}
}()
}
oname := filepath.Join(tmp, filepath.Base(tc.name)+".root")
tname := "tree"
err := process(oname, tname, tc.name)
if err != nil {
t.Fatalf("could not convert %q: %+v", tc.name, err)
}
var (
out = new(strings.Builder)
deep = true
)
err = rcmd.Dump(out, oname, deep, nil)
if err != nil {
t.Fatalf("could not dump ROOT file %q: %+v", oname, err)
}
want, err := os.ReadFile(tc.name + ".txt")
if err != nil {
t.Fatalf("could not load reference file %q: %+v", tc.name, err)
}
if got, want := out.String(), string(want); got != want {
t.Fatalf("invalid root-dump output:\ngot:\n%s\nwant:\n%s\n", got, want)
}
})
}
}