mirror of
https://github.com/ipfs/kubo.git
synced 2025-10-24 15:12:55 +08:00
tests(commands/option) test the OptionValue methods
TODO add tests for remaning, untested methods.
This commit is contained in:
committed by
Juan Batiz-Benet
parent
69374b30be
commit
3c4f628493
36
commands/option_test.go
Normal file
36
commands/option_test.go
Normal file
@ -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.")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user