tests(commands/option) test the OptionValue methods
TODO add tests for remaning, untested methods.
Brian Tiger Chow committed
Nov 11, 2014 at 23:32 UTC
3c4f628493a3355c3a74ffdb68b374cbdb9c7053
1 file changed
+36
commands/option_test.go
new
+36
@@ -0,0 +1,36 @@
1
+package commands
2
+
3
+import "testing"
4
+
5
+func TestOptionValueExtractBoolNotFound(t *testing.T) {
6
+ t.Log("ensure that no error is returned when value is not found")
7
+ optval := &OptionValue{found: false}
8
+ _, _, err := optval.Bool()
9
+ if err != nil {
10
+ t.Fatal("Found was false. Err should have been nil")
11
+ }
12
+
13
+ t.Log("ensure that no error is returned when value is not found (even if value exists)")
14
+ optval = &OptionValue{value: "wrong type: a string", found: false}
15
+ _, _, err = optval.Bool()
16
+ if err != nil {
17
+ t.Fatal("Found was false. Err should have been nil")
18
+ }
19
+}
20
+
21
+func TestOptionValueExtractWrongType(t *testing.T) {
22
+
23
+ t.Log("ensure that error is returned when value if of wrong type")
24
+
25
+ optval := &OptionValue{value: "wrong type: a string", found: true}
26
+ _, _, err := optval.Bool()
27
+ if err == nil {
28
+ t.Fatal("No error returned. Failure.")
29
+ }
30
+
31
+ optval = &OptionValue{value: "wrong type: a string", found: true}
32
+ _, _, err = optval.Int()
33
+ if err == nil {
34
+ t.Fatal("No error returned. Failure.")
35
+ }
36
+}