|
| 1 | +package client |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/http" |
| 5 | +) |
| 6 | + |
| 7 | +// MockserverClient mockserver client |
| 8 | +type MockserverClient struct { |
| 9 | + *BasicHTTPClient |
| 10 | + Config *MockserverConfig |
| 11 | +} |
| 12 | + |
| 13 | +// MockserverConfig holds config information for MockserverClient |
| 14 | +type MockserverConfig struct { |
| 15 | + LocalURL string |
| 16 | + ClusterURL string |
| 17 | +} |
| 18 | + |
| 19 | +// NewMockserverClient returns a mockserver client |
| 20 | +func NewMockserverClient(cfg *MockserverConfig) *MockserverClient { |
| 21 | + return &MockserverClient{ |
| 22 | + Config: cfg, |
| 23 | + BasicHTTPClient: NewBasicHTTPClient(&http.Client{}, cfg.LocalURL), |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +// PutExpectations sets the expectations (i.e. mocked responses) |
| 28 | +func (em *MockserverClient) PutExpectations(body interface{}) error { |
| 29 | + _, err := em.do(http.MethodPut, "/expectation", &body, nil, http.StatusCreated) |
| 30 | + return err |
| 31 | +} |
| 32 | + |
| 33 | +// ClearExpectation clears expectations |
| 34 | +func (em *MockserverClient) ClearExpectation(body interface{}) error { |
| 35 | + _, err := em.do(http.MethodPut, "/clear", &body, nil, http.StatusOK) |
| 36 | + return err |
| 37 | +} |
| 38 | + |
| 39 | +// PathSelector represents the json object used to find expectations by path |
| 40 | +type PathSelector struct { |
| 41 | + Path string `json:"path"` |
| 42 | +} |
| 43 | + |
| 44 | +// HttpRequest represents the httpRequest json object used in the mockserver initializer |
| 45 | +type HttpRequest struct { |
| 46 | + Path string `json:"path"` |
| 47 | +} |
| 48 | + |
| 49 | +// HttpResponse represents the httpResponse json object used in the mockserver initializer |
| 50 | +type HttpResponse struct { |
| 51 | + Body interface{} `json:"body"` |
| 52 | +} |
| 53 | + |
| 54 | +// HttpInitializer represents an element of the initializer array used in the mockserver initializer |
| 55 | +type HttpInitializer struct { |
| 56 | + Request HttpRequest `json:"httpRequest"` |
| 57 | + Response HttpResponse `json:"httpResponse"` |
| 58 | +} |
| 59 | + |
| 60 | +// For OTPE - weiwatchers |
| 61 | + |
| 62 | +// NodeInfoJSON represents an element of the nodes array used to deliver configs to otpe |
| 63 | +type NodeInfoJSON struct { |
| 64 | + ID string `json:"id"` |
| 65 | + NodeAddress []string `json:"nodeAddress"` |
| 66 | +} |
| 67 | + |
| 68 | +// ContractInfoJSON represents an element of the contracts array used to deliver configs to otpe |
| 69 | +type ContractInfoJSON struct { |
| 70 | + ContractAddress string `json:"contractAddress"` |
| 71 | + ContractVersion int `json:"contractVersion"` |
| 72 | + Path string `json:"path"` |
| 73 | + Status string `json:"status"` |
| 74 | +} |
| 75 | + |
| 76 | +// For Adapter endpoints |
| 77 | + |
| 78 | +// AdapterResult represents an int result for an adapter |
| 79 | +type AdapterResult struct { |
| 80 | + Result int `json:"result"` |
| 81 | +} |
| 82 | + |
| 83 | +// AdapterResponse represents a response from an adapter |
| 84 | +type AdapterResponse struct { |
| 85 | + Id string `json:"id"` |
| 86 | + Data AdapterResult `json:"data"` |
| 87 | + Error interface{} `json:"error"` |
| 88 | +} |
0 commit comments