summaryrefslogtreecommitdiffstats
path: root/config_test.go
blob: 3f4c4b51b94983fb8e55308388f852de22a8d65f (plain)
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
package gotop

import (
	"strings"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
	"github.com/xxxserxxx/gotop/v3/widgets"
)

// FIXME This is totally broken since the updates
func TestParse(t *testing.T) {
	tests := []struct {
		i string
		f func(c Config, e error)
	}{
		{
			i: "logdir",
			f: func(c Config, e error) {
				assert.Error(t, e, "invalid config syntax")
			},
		},
		{
			i: "logdir=foo=bar",
			f: func(c Config, e error) {
				assert.NotNil(t, e)
			},
		},
		{
			i: "foo=bar",
			f: func(c Config, e error) {
				assert.NotNil(t, e)
			},
		},
		{
			i: "configdir=abc\nlogdir=bar\nlogfile=errors",
			f: func(c Config, e error) {
				assert.Nil(t, e, "unexpected error")
				assert.Equal(t, "abc", c.ConfigDir)
			},
		},
		{
			i: "CONFIGDIR=abc\nloGdir=bar\nlogFILe=errors",
			f: func(c Config, e error) {
				assert.Nil(t, e, "unexpected error")
				assert.Equal(t, "abc", c.ConfigDir)
			},
		},
		{
			i: "graphhorizontalscale=a",
			f: func(c Config, e error) {
				assert.Error(t, e, "expected invalid value for graphhorizontalscale")
			},
		},
		{
			i: "helpvisible=a",
			f: func(c Config, e error) {
				assert.Error(t, e, "expected invalid value for helpvisible")
			},
		},
		{
			i: "helpvisible=true\nupdateinterval=30\naveragecpu=true\nPerCPULoad=true\ntempscale=100\nstatusbar=true\nnetinterface=eth0\nlayout=minimal\nmaxlogsize=200",
			f: func(c Config, e error) {
				assert.Nil(t, e, "unexpected error")
				assert.Equal(t, true, c.HelpVisible)
				assert.Equal(t, time.Duration(30), c.UpdateInterval)
				assert.Equal(t, true, c.AverageLoad)
				assert.Equal(t, true, c.PercpuLoad)
				assert.Equal(t, widgets.TempScale(100), c.TempScale)
				assert.Equal(t, true, c.Statusbar)
				assert.Equal(t, "eth0", c.NetInterface)
				assert.Equal(t, "minimal", c.Layout)
				assert.Equal(t, int64(200), c.MaxLogSize)
			},
		},
	}
	for _, tc := range tests {
		in := strings.NewReader(tc.i)
		c := Config{}
		e := load(in, &c)
		tc.f(c, e)
	}
}