From 3c4f628493a3355c3a74ffdb68b374cbdb9c7053 Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Tue, 11 Nov 2014 23:32:47 -0800 Subject: [PATCH] tests(commands/option) test the OptionValue methods TODO add tests for remaning, untested methods. --- commands/option_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 commands/option_test.go diff --git a/commands/option_test.go b/commands/option_test.go new file mode 100644 index 000000000..1ca612ee0 --- /dev/null +++ b/commands/option_test.go @@ -0,0 +1,36 @@ +package commands + +import "testing" + +func TestOptionValueExtractBoolNotFound(t *testing.T) { + t.Log("ensure that no error is returned when value is not found") + optval := &OptionValue{found: false} + _, _, err := optval.Bool() + if err != nil { + t.Fatal("Found was false. Err should have been nil") + } + + t.Log("ensure that no error is returned when value is not found (even if value exists)") + optval = &OptionValue{value: "wrong type: a string", found: false} + _, _, err = optval.Bool() + if err != nil { + t.Fatal("Found was false. Err should have been nil") + } +} + +func TestOptionValueExtractWrongType(t *testing.T) { + + t.Log("ensure that error is returned when value if of wrong type") + + optval := &OptionValue{value: "wrong type: a string", found: true} + _, _, err := optval.Bool() + if err == nil { + t.Fatal("No error returned. Failure.") + } + + optval = &OptionValue{value: "wrong type: a string", found: true} + _, _, err = optval.Int() + if err == nil { + t.Fatal("No error returned. Failure.") + } +}