...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package bzltestutil
16
17 import (
18 "fmt"
19 "os"
20 "testing"
21 )
22
23 func TestShouldWrap(t *testing.T) {
24 var tests = []struct {
25 envs map[string]string
26 shouldWrap bool
27 }{
28 {
29 envs: map[string]string{
30 "GO_TEST_WRAP": "0",
31 "XML_OUTPUT_FILE": "",
32 },
33 shouldWrap: false,
34 }, {
35 envs: map[string]string{
36 "GO_TEST_WRAP": "1",
37 "XML_OUTPUT_FILE": "",
38 },
39 shouldWrap: true,
40 }, {
41 envs: map[string]string{
42 "GO_TEST_WRAP": "",
43 "XML_OUTPUT_FILE": "path",
44 },
45 shouldWrap: true,
46 },
47 }
48 for _, tt := range tests {
49 t.Run(fmt.Sprintf("%v", tt.envs), func(t *testing.T) {
50 for k, v := range tt.envs {
51 if v == "" {
52 os.Unsetenv(k)
53 } else {
54 os.Setenv(k, v)
55 }
56 }
57 got := ShouldWrap()
58 if tt.shouldWrap != got {
59 t.Errorf("shouldWrap returned %t, expected %t", got, tt.shouldWrap)
60 }
61 })
62 }
63 }
64
View as plain text