-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_test.go
66 lines (57 loc) · 1.87 KB
/
config_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
package main
import (
"testing"
tcell "github.com/gdamore/tcell/v2"
)
func TestCombineAttributes(t *testing.T) {
testData := []struct {
FgAttrStr string
BgAttrStr string
ExpectedStyle tcell.Style
ExpectErr bool
}{
{"black", "", tcell.StyleDefault.Foreground(tcell.ColorBlack), false},
{"", "", tcell.StyleDefault, false},
{"foo", "", tcell.StyleDefault, true},
{"green, bold", "", tcell.StyleDefault.Foreground(tcell.ColorGreen).Bold(true), false},
{"blue,reverse", "", tcell.StyleDefault.Foreground(tcell.ColorBlue).Reverse(true), false},
{"yellow,", "", tcell.StyleDefault, true},
{"red, foo", "", tcell.StyleDefault, true},
}
for idx, tt := range testData {
style, err := combineAttributes(tt.FgAttrStr, tt.BgAttrStr)
if (err != nil) != tt.ExpectErr {
t.Fatalf("%d. expected error = %t, err = %v", idx, tt.ExpectErr, err)
}
if style != tt.ExpectedStyle {
t.Fatalf("%d. expected attribute (%v) != returned attribute (%v)", idx, tt.ExpectedStyle, style)
}
t.Logf("%d. input = %q %q output = %v, %v", idx, tt.FgAttrStr, tt.BgAttrStr, style, err)
}
}
func TestLoadConfigFile(t *testing.T) {
testData := []struct {
File string
ExpectErr bool
}{
{"examples/kubectl.yml", false},
{"testdata/does-not-exist.yml", false}, // non-existent files are simply ignored
{"testdata/invalid.yml", true},
{"testdata/invalid_regex.yml", true},
{"testdata/invalid_regex2.yml", true},
{"testdata/invalid_color1.yml", true},
{"testdata/invalid_color2.yml", true},
}
for idx, tt := range testData {
cfg, err := loadConfigFile(tt.File)
if (err != nil) != tt.ExpectErr {
t.Errorf("%d. cfg = %v expected error = %t, err = %v", idx, cfg, tt.ExpectErr, err)
}
}
}
func TestLoadConfig(t *testing.T) {
_, err := loadConfig("examples/kubectl.yml", "testdata")
if err != nil {
t.Fatalf("Failed to load test configuration: %v", err)
}
}