-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patharguments_test.go
60 lines (49 loc) · 1.36 KB
/
arguments_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
// (c) 2022 Rick Arnold. Licensed under the BSD license (see LICENSE).
package props
import (
"os"
"testing"
)
func TestArgumentsGet(t *testing.T) {
a := &Arguments{}
os.Args = make([]string, 0)
os.Args = append(os.Args, "prog")
os.Args = append(os.Args, "--props.test.val1=abc")
os.Args = append(os.Args, "--props.test.val2=")
val, ok := a.Get("props.test.val1")
if !ok || val != "abc" {
t.Errorf("want: true, 'abc'; got: %t, '%s'", ok, val)
}
val, ok = a.Get("props.test.val2")
if !ok || val != "" {
t.Errorf("want: true, ''; got: %t, '%s'", ok, val)
}
val, ok = a.Get("props.test.val3")
if ok || val != "" {
t.Errorf("want: false, ''; got %t, '%s'", ok, val)
}
a.Prefix = "--props."
val, ok = a.Get("test.val1")
if !ok || val != "abc" {
t.Errorf("want: true, 'abc'; got: %t, '%s'", ok, val)
}
}
func TestArgumentsGetDefault(t *testing.T) {
a := &Arguments{Prefix: "--props."}
os.Args = make([]string, 0)
os.Args = append(os.Args, "prog")
os.Args = append(os.Args, "--props.test.val1=abc")
os.Args = append(os.Args, "--props.test.val2=")
val := a.GetDefault("test.val1", "zzz")
if val != "abc" {
t.Errorf("want: 'abc'; got: '%s'", val)
}
val = a.GetDefault("test.val2", "def")
if val != "" {
t.Errorf("want: ''; got: '%s'", val)
}
val = a.GetDefault("test.val3", "ghi")
if val != "ghi" {
t.Errorf("want: 'ghi'; got: '%s'", val)
}
}