tpl: Cast IsSet key to int for indexed types

Don't assume that the user sends an int as the key when checking against
indexed types.

Fixes #3681
This commit is contained in:
Cameron Moore
2018-10-02 20:29:20 -05:00
committed by Bjørn Erik Pedersen
parent d3b81ee58e
commit 0d5110d033
2 changed files with 15 additions and 9 deletions

View File

@@ -438,22 +438,24 @@ func TestIsSet(t *testing.T) {
key interface{}
expect bool
isErr bool
errStr string
}{
{[]interface{}{1, 2, 3, 5}, 2, true, false, ""},
{[]interface{}{1, 2, 3, 5}, 22, false, false, ""},
{[]interface{}{1, 2, 3, 5}, 2, true, false},
{[]interface{}{1, 2, 3, 5}, "2", true, false},
{[]interface{}{1, 2, 3, 5}, 2.0, true, false},
{map[string]interface{}{"a": 1, "b": 2}, "b", true, false, ""},
{map[string]interface{}{"a": 1, "b": 2}, "bc", false, false, ""},
{[]interface{}{1, 2, 3, 5}, 22, false, false},
{time.Now(), "Day", false, false, ""},
{nil, "nil", false, false, ""},
{map[string]interface{}{"a": 1, "b": 2}, "b", true, false},
{map[string]interface{}{"a": 1, "b": 2}, "bc", false, false},
{time.Now(), "Day", false, false},
{nil, "nil", false, false},
{[]interface{}{1, 2, 3, 5}, TstX{}, false, true},
} {
errMsg := fmt.Sprintf("[%d] %v", i, test)
result, err := ns.IsSet(test.a, test.key)
if test.isErr {
assert.EqualError(t, err, test.errStr, errMsg)
continue
}