-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatcher-obj.go
More file actions
47 lines (39 loc) · 1.1 KB
/
matcher-obj.go
File metadata and controls
47 lines (39 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package arp
import (
"errors"
"fmt"
"reflect"
)
type ObjectMatcher struct {
Properties map[interface{}]interface{}
Sorted bool
FieldMatcherProps
}
func (m *ObjectMatcher) Parse(parentNode interface{}, node map[interface{}]interface{}) error {
if node[TEST_KEY_PROPERTIES] != nil {
if properties, ok := node[TEST_KEY_PROPERTIES].(map[interface{}]interface{}); ok {
m.Properties = properties
} else {
return errors.New(ObjectPrintf(fmt.Sprintf(MalformedDefinitionFmt, TEST_KEY_PROPERTIES, TYPE_OBJ), parentNode))
}
}
return m.ParseProps(node)
}
func (m *ObjectMatcher) Match(responseValue interface{}, datastore *DataStore) (bool, DataStore, error) {
var err error
store := NewDataStore()
m.ErrorStr = ""
var typedResponseValue map[string]interface{}
switch t := responseValue.(type) {
case map[string]interface{}:
typedResponseValue = t
default:
m.ErrorStr = fmt.Sprintf(MismatchedMatcher, TYPE_OBJ, reflect.TypeOf(responseValue))
return false, store, nil
}
m.ErrorStr = "{}"
if m.DSName != "" {
err = store.PutVariable(m.DSName, typedResponseValue)
}
return true, store, err
}