test: fix most integration tests (live)

This commit is contained in:
James Houlahan
2020-04-09 10:24:58 +02:00
parent bafd4e714e
commit fec5f2d3c3
18 changed files with 124 additions and 104 deletions

View File

@ -29,20 +29,20 @@ type fakeCall struct {
request []byte
}
func (cntrl *Controller) recordCall(method, path string, request []byte) {
cntrl.lock.Lock()
defer cntrl.lock.Unlock()
func (ctl *Controller) recordCall(method, path string, request []byte) {
ctl.lock.Lock()
defer ctl.lock.Unlock()
cntrl.calls = append(cntrl.calls, &fakeCall{
ctl.calls = append(ctl.calls, &fakeCall{
method: method,
path: path,
request: request,
})
}
func (cntrl *Controller) PrintCalls() {
func (ctl *Controller) PrintCalls() {
fmt.Println("API calls:")
for idx, call := range cntrl.calls {
for idx, call := range ctl.calls {
fmt.Printf("%02d: [%s] %s\n", idx+1, call.method, call.path)
if call.request != nil && string(call.request) != "null" {
fmt.Printf("\t%s\n", call.request)
@ -50,8 +50,8 @@ func (cntrl *Controller) PrintCalls() {
}
}
func (cntrl *Controller) WasCalled(method, path string, expectedRequest []byte) bool {
for _, call := range cntrl.calls {
func (ctl *Controller) WasCalled(method, path string, expectedRequest []byte) bool {
for _, call := range ctl.calls {
if call.method != method && call.path != path {
continue
}
@ -64,9 +64,9 @@ func (cntrl *Controller) WasCalled(method, path string, expectedRequest []byte)
return false
}
func (cntrl *Controller) GetCalls(method, path string) [][]byte {
func (ctl *Controller) GetCalls(method, path string) [][]byte {
requests := [][]byte{}
for _, call := range cntrl.calls {
for _, call := range ctl.calls {
if call.method == method && call.path == path {
requests = append(requests, call.request)
}