-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmdline_test.go
92 lines (73 loc) · 3.77 KB
/
cmdline_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
package core
import (
"github.com/stretchr/testify/assert"
"os"
"testing"
)
func TestSimpleCommandLinePropertySource_ContainsOption(t *testing.T) {
commandLinePropertySource := NewSimpleCommandLinePropertySource(getTestApplicationArguments())
assert.True(t, commandLinePropertySource.ContainsOption("procyon.application.name"))
assert.True(t, commandLinePropertySource.ContainsOption("procyon.server.port"))
}
func TestSimpleCommandLinePropertySource_ContainsProperty(t *testing.T) {
commandLinePropertySource := NewSimpleCommandLinePropertySource(getTestApplicationArguments())
assert.True(t, commandLinePropertySource.ContainsProperty("procyon.application.name"))
assert.True(t, commandLinePropertySource.ContainsProperty("procyon.server.port"))
}
func TestSimpleCommandLinePropertySource_GetName(t *testing.T) {
commandLinePropertySource := NewSimpleCommandLinePropertySource(getTestApplicationArguments())
assert.Equal(t, ProcyonApplicationCommandLinePropertySource, commandLinePropertySource.GetName())
}
func TestSimpleCommandLinePropertySource_GetNonOptionArgs(t *testing.T) {
commandLinePropertySource := NewSimpleCommandLinePropertySource(getTestApplicationArguments())
nonOptionArgs := commandLinePropertySource.GetNonOptionArgs()
assert.Contains(t, nonOptionArgs, "-debug")
}
func TestSimpleCommandLinePropertySource_GetProperty(t *testing.T) {
commandLinePropertySource := NewSimpleCommandLinePropertySource(getTestApplicationArguments())
result := commandLinePropertySource.GetProperty("procyon.application.name")
assert.Equal(t, "\"Test Application\"", result)
result = commandLinePropertySource.GetProperty("procyon.server.port")
assert.Equal(t, "8080,8090", result)
}
func TestSimpleCommandLinePropertySource_GetPropertyNames(t *testing.T) {
commandLinePropertySource := NewSimpleCommandLinePropertySource(getTestApplicationArguments())
propertyNames := commandLinePropertySource.GetPropertyNames()
assert.Contains(t, propertyNames, "procyon.application.name")
assert.Contains(t, propertyNames, "procyon.server.port")
}
func TestSimpleCommandLinePropertySource_GetOptionValues(t *testing.T) {
commandLinePropertySource := NewSimpleCommandLinePropertySource(getTestApplicationArguments())
values := commandLinePropertySource.GetOptionValues("procyon.server.port")
assert.Contains(t, values, "8080")
assert.Contains(t, values, "8090")
}
func TestSimpleCommandLinePropertySource_GetSource(t *testing.T) {
commandLinePropertySource := NewSimpleCommandLinePropertySource(getTestApplicationArguments())
assert.NotNil(t, commandLinePropertySource.GetSource())
}
func getTestApplicationArguments() []string {
var args = make([]string, 0)
args = append(args, os.Args...)
args = append(args, "--procyon.application.name=\"Test Application\"")
args = append(args, "--procyon.server.port=8080")
args = append(args, "--procyon.server.port=8090")
args = append(args, "-debug")
return args
}
func TestSimpleCommandLineArgsParser_Parse(t *testing.T) {
commandLineParser := NewCommandLineArgsParser()
args, err := commandLineParser.Parse(getTestApplicationArguments())
assert.Nil(t, err)
assert.NotNil(t, args)
assert.Equal(t, 2, len(args.optionArgs))
assert.Equal(t, 1, len(args.getOptionValues("procyon.application.name")))
assert.Equal(t, 2, len(args.getOptionValues("procyon.server.port")))
assert.Contains(t, args.getOptionNames(), "procyon.application.name")
assert.Contains(t, args.getOptionNames(), "procyon.server.port")
assert.True(t, args.containsOption("procyon.application.name"))
assert.True(t, args.containsOption("procyon.server.port"))
assert.Contains(t, args.getOptionValues("procyon.application.name"), "\"Test Application\"")
assert.Contains(t, args.getOptionValues("procyon.server.port"), "8080")
assert.Contains(t, args.getOptionValues("procyon.server.port"), "8090")
}