mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-08 04:20:17 +00:00
updated coverage for timeout path lookup
Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
@@ -114,24 +114,17 @@ func FindNodesWithoutDeserializing(node *yaml.Node, jsonPath string) ([]*yaml.No
|
|||||||
|
|
||||||
// this can spin out, to lets gatekeep it.
|
// this can spin out, to lets gatekeep it.
|
||||||
done := make(chan bool)
|
done := make(chan bool)
|
||||||
eChan := make(chan error)
|
|
||||||
var results []*yaml.Node
|
var results []*yaml.Node
|
||||||
timeout, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
timeout, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
go func(d chan bool, e chan error) {
|
go func(d chan bool) {
|
||||||
var er error
|
results, _ = path.Find(node)
|
||||||
results, er = path.Find(node)
|
|
||||||
if er != nil {
|
|
||||||
e <- er
|
|
||||||
}
|
|
||||||
done <- true
|
done <- true
|
||||||
}(done, eChan)
|
}(done)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
return results, nil
|
return results, nil
|
||||||
case er := <-eChan:
|
|
||||||
return nil, er
|
|
||||||
case <-timeout.Done():
|
case <-timeout.Done():
|
||||||
return nil, fmt.Errorf("node lookup timeout exceeded")
|
return nil, fmt.Errorf("node lookup timeout exceeded")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -913,3 +913,20 @@ func TestDetermineJSONWhitespaceLength_None(t *testing.T) {
|
|||||||
someBytes := []byte(`{"hello": "world"}`)
|
someBytes := []byte(`{"hello": "world"}`)
|
||||||
assert.Equal(t, 0, DetermineWhitespaceLength(string(someBytes)))
|
assert.Equal(t, 0, DetermineWhitespaceLength(string(someBytes)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTimeoutFind(t *testing.T) {
|
||||||
|
a := &yaml.Node{
|
||||||
|
Value: "chicken",
|
||||||
|
}
|
||||||
|
b := &yaml.Node{
|
||||||
|
Value: "nuggets",
|
||||||
|
}
|
||||||
|
|
||||||
|
// loopy loop.
|
||||||
|
a.Content = append(a.Content, b)
|
||||||
|
b.Content = append(b.Content, a)
|
||||||
|
|
||||||
|
nodes, err := FindNodesWithoutDeserializing(a, "$..nuggets")
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Nil(t, nodes)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user