-
Notifications
You must be signed in to change notification settings - Fork 8
/
config_test.go
191 lines (168 loc) · 4.59 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
Copyright © 2020, 2023 M.Watermann, 10247 Berlin, Germany
All rights reserved
EMail : <[email protected]>
*/
package kaliber
//lint:file-ignore ST1017 - I prefer Yoda conditions
import (
"flag"
"path/filepath"
"reflect"
"testing"
"github.com/mwat56/ini"
)
// `parseFlagDebug()` calls `parseFlags()` and returns `AppArgs`.
//
// This function is meant for unit testing only.
func parseFlagDebug() *TAppArgs {
flag.CommandLine = flag.NewFlagSet(`Kaliber`, flag.ExitOnError)
// Define some flags used by `testing` to avoid
// bailing out during the test.
var coverprofile, panic, run, testlogfile, timeout string
flag.CommandLine.StringVar(&coverprofile, `test.coverprofile`, coverprofile,
"coverprofile for tests")
flag.CommandLine.StringVar(&panic, `test.paniconexit0`, panic,
"panic for tests")
flag.CommandLine.StringVar(&run, `test.run`, run,
"run for tests")
flag.CommandLine.StringVar(&testlogfile, `test.testlogfile`, testlogfile,
"testlogfile for tests")
flag.CommandLine.StringVar(&timeout, `test.timeout`, timeout,
"timeout for tests")
parseFlags()
return &AppArgs
} // parseFlagDebug
// `readFlagsDebug()` calls `readFlags()` and returns `AppArgs`.
//
// This function is meant for unit testing only.
func readFlagsDebug() *TAppArgs {
flag.CommandLine = flag.NewFlagSet(`Kaliber`, flag.ExitOnError)
AppArgs = TAppArgs{}
// Set up some required values:
AppArgs.DataDir, _ = filepath.Abs(`./`)
// AppArgs.dump = true
AppArgs.LibName = `testing`
AppArgs.libPath = `/var/opt/Calibre`
readFlags()
return &AppArgs
} // readFlagsDebug()
// `setFlagsDebug()` calls `setFlags()` and returns `AppArgs`.
//
// This function is meant for unit testing only.
func setFlagsDebug() *TAppArgs {
flag.CommandLine = flag.NewFlagSet(`Kaliber`, flag.ExitOnError)
var ini1 ini.TIniList
// Clear/reset the INI values to simulate missing INI file(s):
iniValues = tArguments{*ini1.GetSection(``)}
setFlags()
return &AppArgs
} // setFlagsDebug()
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
func Test_parseFlagDebug(t *testing.T) {
expected := &TAppArgs{}
tests := []struct {
name string
want *TAppArgs
}{
// TODO: Add test cases.
{" 1", expected},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := parseFlagDebug(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseFlagDebug() = %s,\nwant %s", got, tt.want)
}
})
}
} // Test_parseFlagDebug()
func Test_readFlagsDebug(t *testing.T) {
expected := &TAppArgs{
Addr: `:8383`,
BooksPerPage: 24,
DataDir: `/home/matthias/devel/Go/src/github.com/mwat56/kaliber`,
Lang: `en`,
LibName: `testing`,
libPath: `/var/opt/Calibre`,
port: 8383,
Realm: `eBooks Host`,
SessionDir: `/home/matthias/devel/Go/src/github.com/mwat56/kaliber/sessions`,
sessionTTL: 1200,
sidName: `sid`,
Theme: `dark`,
}
tests := []struct {
name string
want *TAppArgs
}{
// TODO: Add test cases.
{" 1", expected},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := readFlagsDebug(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("readFlagsDebug() = %s,\nwant %s", got, tt.want)
}
})
}
AppArgs = TAppArgs{} // clear/reset the structure
} // Test_readFlagsDebug()
func Test_readIniFiles(t *testing.T) {
tests := []struct {
name string
}{
// TODO: Add test cases.
{" 1"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
readIniFiles()
})
}
} // Test_readIniFiles()
func Test_setFlagsDebug(t *testing.T) {
expected := &TAppArgs{
AuthAll: true,
BooksPerPage: 24,
DataDir: `/home/matthias/devel/Go/src/github.com/mwat56/kaliber`,
delWhitespace: true,
GZip: true,
Lang: `en`,
libPath: `/var/opt/Calibre`,
listen: `127.0.0.1`,
port: 8383,
Realm: `eBooks Host`,
sessionTTL: 1200,
sidName: `sid`,
Theme: `dark`,
}
tests := []struct {
name string
want *TAppArgs
}{
// TODO: Add test cases.
{" 1", expected},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := setFlagsDebug(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("setFlagsDebug() = %s,\nwant %s", got, tt.want)
}
})
}
AppArgs = TAppArgs{} // clear/reset the structure
} // Test_setFlagsDebug()
func TestShowHelp(t *testing.T) {
_ = setFlagsDebug()
tests := []struct {
name string
}{
// TODO: Add test cases.
{" 1"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ShowHelp()
})
}
} // TestShowHelp()