/
recorder.go
38 lines (34 loc) · 918 Bytes
/
recorder.go
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
package recorder
import (
"fmt"
"time"
"github.com/steinfletcher/apitest"
)
func recordInput(recorder *apitest.Recorder, source, operation, body string) {
recorder.AddMessageRequest(apitest.MessageRequest{
Source: apitest.SystemUnderTestDefaultName,
Target: source,
Header: operation,
Body: body,
Timestamp: time.Now(),
})
}
func recordOutput(recorder *apitest.Recorder, source, operation, body string, err error) {
if err != nil {
recorder.AddMessageResponse(apitest.MessageResponse{
Source: source,
Target: apitest.SystemUnderTestDefaultName,
Header: "Error",
Body: fmt.Sprintf("Error: %s", err.Error()),
Timestamp: time.Now(),
})
} else {
recorder.AddMessageResponse(apitest.MessageResponse{
Source: source,
Target: apitest.SystemUnderTestDefaultName,
Header: operation,
Body: body,
Timestamp: time.Now(),
})
}
}