-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchannels_test.go
38 lines (32 loc) · 1.1 KB
/
channels_test.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 channels_test
import (
"context"
"encoding/json"
"errors"
"io"
"github.com/wakumaku/go-zulip"
)
// mockClient is a mock implementation of zulip.RESTClient
// just for testing purposes, cannot be used concurrently on the same instance
type mockClient struct {
response string
method string
path string
paramsSent map[string]any // sort of spy for testing input parameters
}
func (mc *mockClient) DoRequest(ctx context.Context, method, path string, data map[string]any, response zulip.APIResponse, opts ...zulip.DoRequestOption) error {
mc.method = method
mc.path = path
mc.paramsSent = data
return json.Unmarshal([]byte(mc.response), response)
}
func (mc *mockClient) DoFileRequest(ctx context.Context, method, path string, fileName string, file io.Reader, response zulip.APIResponse, opts ...zulip.DoRequestOption) error {
return errors.New("not implemented")
}
// createMockClient creates a mockClient with the given response
// TODO: other complex behaviours: 4xx, timeouts, etc.
func createMockClient(response string) zulip.RESTClient {
return &mockClient{
response: response,
}
}