forked from rapidpro/mailroom
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add elastic tests, add query field to flowstart
- Loading branch information
1 parent
358626d
commit 5c286e0
Showing
13 changed files
with
256 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package search | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"net/http/httptest" | ||
) | ||
|
||
// MockElasticServer is a mock HTTP server/endpoint that can be used to test elastic queries | ||
type MockElasticServer struct { | ||
Server *httptest.Server | ||
LastBody string | ||
NextResponse string | ||
} | ||
|
||
// NewMockElasticServer creates a new mock elastic server | ||
func NewMockElasticServer() *MockElasticServer { | ||
mock := &MockElasticServer{} | ||
mock.Server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
// scrolling of results, we are always one page, so return empty hits | ||
if r.URL.String() == "/_search/scroll" { | ||
w.WriteHeader(200) | ||
w.Write([]byte(` | ||
{ | ||
"_scroll_id": "anything==", | ||
"took": 7, | ||
"timed_out": false, | ||
"_shards": { | ||
"total": 1, | ||
"successful": 1, | ||
"skipped": 0, | ||
"failed": 0 | ||
}, | ||
"hits": { | ||
"total": 1000, | ||
"max_score": null, | ||
"hits": [] | ||
} | ||
} | ||
`)) | ||
return | ||
} | ||
|
||
// otherwise read our next body and return our next response | ||
body, _ := ioutil.ReadAll(r.Body) | ||
mock.LastBody = string(body) | ||
|
||
fmt.Println(r.URL) | ||
fmt.Println(mock.LastBody) | ||
|
||
w.WriteHeader(200) | ||
w.Write([]byte(mock.NextResponse)) | ||
mock.NextResponse = "" | ||
})) | ||
return mock | ||
} | ||
|
||
// Close closes our HTTP server | ||
func (m *MockElasticServer) Close() { | ||
m.Server.Close() | ||
} | ||
|
||
// URL returns the URL to call this server | ||
func (m *MockElasticServer) URL() string { | ||
return m.Server.URL | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.