-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
37 lines (32 loc) · 926 Bytes
/
Copy pathmain_test.go
File metadata and controls
37 lines (32 loc) · 926 Bytes
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
package main
import (
"flag"
"os"
"testing"
)
func TestParseCommandLine(t *testing.T) {
tests := []struct {
name string
args []string
expected bool
}{
{"version flag", []string{"-version"}, false},
{"valid config", []string{"-c", "/tmp/config.yaml"}, true},
{"default config", []string{}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Reset flags
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
configFilePath = flag.String("c", "/etc/bucketsyncd/config.yaml", "Configuration file location")
showVersion = flag.Bool("version", false, "Show version information")
help = flag.Bool("h", false, "Usage information")
// Set args
os.Args = append([]string{"bucketsyncd"}, tt.args...)
result := parseCommandLine()
if result != tt.expected {
t.Errorf("parseCommandLine() = %v, want %v", result, tt.expected)
}
})
}
}