-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_test.go
85 lines (76 loc) · 2.64 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
package main
import (
"os"
"testing"
)
const (
Command = "linker"
DefaultPWD = "/PWD/"
DefaultHome = "/HOME/"
ShortTarget = "/T/"
LongTarget = "/TARGET/"
ShortSource = "/S/"
LongSource = "/SOURCE/"
)
func (c *Config) Reset() {
c.Source = DefaultPWD
c.Target = DefaultHome
c.Dryrun = false
c.Force = false
c.Debug = false
}
// TODO: Prints a bunch when enabling debug mode, should be handled with a testLogger (that later can be used for log verification)
func TestParseFlags(t *testing.T) {
var cases = []struct {
args []string
expectedSource string
expectedTarget string
expectedDryrun bool
expectedForce bool
expectedDebug bool
}{
{[]string{Command}, DefaultPWD, DefaultHome, false, false, false},
{[]string{Command, "-t", ShortTarget}, DefaultPWD, ShortTarget, false, false, false},
{[]string{Command, "-target", LongTarget}, DefaultPWD, LongTarget, false, false, false},
{[]string{Command, "-s", ShortSource}, ShortSource, DefaultHome, false, false, false},
{[]string{Command, "-source", LongSource}, LongSource, DefaultHome, false, false, false},
{[]string{Command, "-n"}, DefaultPWD, DefaultHome, true, false, false},
{[]string{Command, "-dry-run"}, DefaultPWD, DefaultHome, true, false, false},
{[]string{Command, "-f"}, DefaultPWD, DefaultHome, false, true, false},
{[]string{Command, "-force"}, DefaultPWD, DefaultHome, false, true, false},
{[]string{Command, "-d"}, DefaultPWD, DefaultHome, false, false, true},
{[]string{Command, "-debug"}, DefaultPWD, DefaultHome, false, false, true},
{[]string{Command, "-s", LongSource, "-t", LongTarget, "-n", "-f", "-d"}, LongSource, LongTarget, true, true, true},
}
oldArgs := os.Args
defer func() { os.Args = oldArgs }()
for i, c := range cases {
// Reset & Setup
config.Reset()
os.Args = c.args
// Execute
config.ParseFlags()
// Verify
if config.Source != c.expectedSource {
t.Errorf("[CASE:%d] Source is %s expected %s", i, config.Source, c.expectedSource)
}
if config.Target != c.expectedTarget {
t.Errorf("[CASE:%d] Target is %s expected %s", i, config.Target, c.expectedTarget)
}
if config.Dryrun != c.expectedDryrun {
t.Errorf("[CASE:%d] Dryrun is %t expected %t", i, config.Dryrun, c.expectedDryrun)
}
if config.Force != c.expectedForce {
t.Errorf("[CASE:%d] Force is %t expected %t", i, config.Force, c.expectedForce)
}
if config.Debug != c.expectedDebug {
t.Errorf("[CASE:%d] Debug is %t expected %t", i, config.Debug, c.expectedDebug)
}
}
}
// TODO Verif: verification of arguments (source & target)
// source nonPath => error
// target nonDir => error
// target nonPath => error
func TestVerify(t *testing.T) {
}