Repository navigation
Expand file tree
/
Copy pathchannel_skip_truncate_test.go
More file actions
65 lines (51 loc) · 1.64 KB
/
Copy pathchannel_skip_truncate_test.go
File metadata and controls
65 lines (51 loc) · 1.64 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package stream_chat
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func newMockClient(t *testing.T, handler http.HandlerFunc) *Client {
t.Helper()
srv := httptest.NewServer(handler)
t.Cleanup(srv.Close)
c, err := NewClient("key", "secret")
require.NoError(t, err)
c.BaseURL = srv.URL
return c
}
func TestChannel_DeleteSkipTruncate(t *testing.T) {
ctx := context.Background()
var query string
c := newMockClient(t, func(w http.ResponseWriter, r *http.Request) {
query = r.URL.Query().Get("skip_truncate")
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"duration":"0.01"}`))
})
ch := &Channel{Type: "messaging", ID: "chan", client: c}
_, err := ch.Delete(ctx)
require.NoError(t, err)
assert.Empty(t, query)
_, err = ch.Delete(ctx, DeleteWithSkipTruncate())
require.NoError(t, err)
assert.Equal(t, "true", query)
}
func TestClient_DeleteChannelsSkipTruncate(t *testing.T) {
ctx := context.Background()
var body map[string]interface{}
c := newMockClient(t, func(w http.ResponseWriter, r *http.Request) {
body = nil
require.NoError(t, json.NewDecoder(r.Body).Decode(&body))
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write([]byte(`{"duration":"0.01","task_id":"task"}`))
})
_, err := c.DeleteChannels(ctx, []string{"messaging:chan"}, false)
require.NoError(t, err)
assert.NotContains(t, body, "skip_truncate")
_, err = c.DeleteChannels(ctx, []string{"messaging:chan"}, false, DeleteWithSkipTruncate())
require.NoError(t, err)
assert.Equal(t, true, body["skip_truncate"])
}