test string slice as string ; invalid json but valid when wrapped
This commit is contained in:
parent
503f01bddd
commit
c2e8efc82b
|
@ -31,7 +31,7 @@ func TestSimpleString(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func TestStringSlice(t *testing.T) {
|
func TestStringSlice(t *testing.T) {
|
||||||
p := Parameter{Parsed: false, File: false, Value: "some-string"}
|
p := Parameter{Parsed: false, File: false, Value: `["str1", "str2"]`}
|
||||||
|
|
||||||
err := p.Parse()
|
err := p.Parse()
|
||||||
|
|
||||||
|
@ -45,14 +45,31 @@ func TestStringSlice(t *testing.T) {
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
cast, canCast := p.Value.(string)
|
slice, canCast := p.Value.([]interface{})
|
||||||
if !canCast {
|
if !canCast {
|
||||||
t.Errorf("expected parameter to be a string")
|
t.Errorf("expected parameter to be a []interface{}")
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
if cast != "some-string" {
|
if len(slice) != 2 {
|
||||||
t.Errorf("expected parameter to equal 'some-string', got '%s'", cast)
|
t.Errorf("expected 2 values, got %d", len(slice))
|
||||||
t.FailNow()
|
t.FailNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
results := []string{"str1", "str2"}
|
||||||
|
|
||||||
|
for i, res := range results {
|
||||||
|
|
||||||
|
cast, canCast := slice[i].(string)
|
||||||
|
if !canCast {
|
||||||
|
t.Errorf("expected parameter %d to be a []string", i)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if cast != res {
|
||||||
|
t.Errorf("expected first value to be '%s', got '%s'", res, cast)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue