mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-22 07:53:38 +01:00
Add TestEvalWithArrayOfValuesAndInvalidIndex
This commit is contained in:
parent
e3038f0e80
commit
57ef931d38
@ -41,7 +41,7 @@ func extractValue(currentKey string, value interface{}) interface{} {
|
||||
tmp := strings.SplitN(currentKey, "[", 3)
|
||||
arrayIndex, err := strconv.Atoi(strings.Replace(tmp[1], "]", "", 1))
|
||||
if err != nil {
|
||||
return value
|
||||
return nil
|
||||
}
|
||||
currentKey := tmp[0]
|
||||
// if currentKey contains only an index (i.e. [0] or 0)
|
||||
|
@ -84,6 +84,16 @@ func TestEvalWithArrayOfValues(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvalWithArrayOfValuesAndInvalidIndex(t *testing.T) {
|
||||
path := "ids[wat]"
|
||||
data := `{"ids": [1, 2]}`
|
||||
|
||||
_, _, err := Eval(path, []byte(data))
|
||||
if err == nil {
|
||||
t.Error("Expected an error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvalWithRootArrayOfValues(t *testing.T) {
|
||||
path := "[1]"
|
||||
data := `[1, 2]`
|
||||
|
Loading…
Reference in New Issue
Block a user