-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain_test.go
More file actions
97 lines (83 loc) · 2.37 KB
/
Copy pathmain_test.go
File metadata and controls
97 lines (83 loc) · 2.37 KB
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
package main
import (
"bytes"
"flag"
"fmt"
"strings"
"testing"
"github.com/tenntenn/golden"
)
var flagUpdate bool
func init() {
flag.BoolVar(&flagUpdate, "update", false, "update golden files")
}
func TestCLI_Run(t *testing.T) {
t.Parallel()
for _, outputType := range []string{"mermaid", "plantuml"} {
outputType := outputType
t.Run(outputType, func(t *testing.T) {
t.Parallel()
cases := map[string]struct {
args string
in string
wantErr bool
}{
"simple": {
args: "-config ./testdata/simple/config.yaml ./testdata/simple/trace.json",
},
"simple:no-response": {
args: "-config ./testdata/simple/config.yaml -no-response ./testdata/simple/trace.json",
},
"simple:no-response-not-skip-self-call": {
args: "-config ./testdata/simple/config.yaml -no-response -skip-self-call=false ./testdata/simple/trace.json",
},
"simple:not-no-response-not-skip-self-call": {
args: "-config ./testdata/simple/config.yaml -no-response=false -skip-self-call=false ./testdata/simple/trace.json",
},
"complex": {
args: "./testdata/complex/trace.json",
},
"complex:no-response": {
args: "-no-response ./testdata/complex/trace.json",
},
"complex:no-response-not-skip-self-call": {
args: "-no-response -skip-self-call=false ./testdata/complex/trace.json",
},
"complex:not-no-response-not-skip-self-call": {
args: "-no-response=false -skip-self-call=false ./testdata/complex/trace.json",
},
}
for name, tt := range cases {
name, tt := name, tt
t.Run(name, func(t *testing.T) {
t.Parallel()
var stdout, stderr bytes.Buffer
cli := &CLI{
Stdout: &stdout,
Stderr: &stderr,
Stdin: strings.NewReader(tt.in),
}
args := append([]string{"-type", outputType}, strings.Split(tt.args, " ")...)
err := cli.Run(args)
if tt.wantErr {
if err == nil {
t.Error("want error, but got nil")
}
} else {
if err != nil {
t.Errorf("want nil, but got an error: %v", err)
}
}
name = fmt.Sprintf("%s_%s", outputType, name)
c := golden.New(t, flagUpdate, "testdata/golden", name)
if diff := c.Check("_stdout", &stdout); diff != "" {
t.Error("stdout\n", diff)
}
if diff := c.Check("_stderr", &stderr); diff != "" {
t.Error("stderr\n", diff)
}
})
}
})
}
}