-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_response.go
38 lines (27 loc) · 1.29 KB
/
test_response.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 stretchr
import (
"bytes"
"fmt"
"github.com/stretchr/sdk-go/api"
"github.com/stretchr/sdk-go/common"
"io/ioutil"
"net/http"
)
var TestChangeInfo = api.ChangeInfo{common.ChangeInfoPublicFieldCreated: 1, common.ChangeInfoPublicFieldUpdated: 2, common.ChangeInfoPublicFieldDeleted: 3, common.ChangeInfoPublicFieldDeltas: []interface{}{map[string]interface{}{common.DataFieldID: "ABC"}, map[string]interface{}{common.DataFieldID: "DEF"}}}
func NewTestResponse(status float64, data interface{}, errors []map[string]interface{}, context string, changeInfo api.ChangeInfo) *api.Response {
httpResponse := new(http.Response)
sro := map[string]interface{}{common.ResponseObjectFieldStatusCode: status,
common.ResponseObjectFieldData: data,
common.ResponseObjectFieldErrors: errors,
common.ResponseObjectFieldChangeInfo: changeInfo,
common.ResponseObjectFieldContext: context}
session := api.NewSession("project", "company", "apiKey")
responseBytes, _ := session.Codec().Marshal(sro, nil)
httpResponse.Body = ioutil.NopCloser(bytes.NewBuffer(responseBytes))
httpResponse.Header = make(map[string][]string)
response, newResponseErr := api.NewResponse(session, httpResponse)
if newResponseErr != nil {
panic(fmt.Sprintf("NewTestResponse: %s", newResponseErr))
}
return response
}