-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathoptions_test.go
80 lines (60 loc) · 2.01 KB
/
options_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
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package meilisearch
import (
"crypto/tls"
"github.com/stretchr/testify/require"
"net/http"
"testing"
)
func TestOptions_WithCustomClient(t *testing.T) {
meili := setup(t, "", WithCustomClient(http.DefaultClient))
require.NotNil(t, meili)
m, ok := meili.(*meilisearch)
require.True(t, ok)
require.Equal(t, m.client.client, http.DefaultClient)
}
func TestOptions_WithCustomClientWithTLS(t *testing.T) {
tl := new(tls.Config)
meili := setup(t, "", WithCustomClientWithTLS(tl))
require.NotNil(t, meili)
m, ok := meili.(*meilisearch)
require.True(t, ok)
tr, ok := m.client.client.Transport.(*http.Transport)
require.True(t, ok)
require.Equal(t, tr.TLSClientConfig, tl)
}
func TestOptions_WithAPIKey(t *testing.T) {
meili := setup(t, "", WithAPIKey("foobar"))
require.NotNil(t, meili)
m, ok := meili.(*meilisearch)
require.True(t, ok)
require.Equal(t, m.client.apiKey, "foobar")
}
func TestOptions_WithContentEncoding(t *testing.T) {
meili := setup(t, "", WithContentEncoding(GzipEncoding, DefaultCompression))
require.NotNil(t, meili)
m, ok := meili.(*meilisearch)
require.True(t, ok)
require.Equal(t, m.client.contentEncoding, GzipEncoding)
require.NotNil(t, m.client.encoder)
}
func TestOptions_WithCustomRetries(t *testing.T) {
meili := setup(t, "", WithCustomRetries([]int{http.StatusInternalServerError}, 10))
require.NotNil(t, meili)
m, ok := meili.(*meilisearch)
require.True(t, ok)
require.True(t, m.client.retryOnStatus[http.StatusInternalServerError])
require.Equal(t, m.client.maxRetries, uint8(10))
meili = setup(t, "", WithCustomRetries([]int{http.StatusInternalServerError}, 0))
require.NotNil(t, meili)
m, ok = meili.(*meilisearch)
require.True(t, ok)
require.True(t, m.client.retryOnStatus[http.StatusInternalServerError])
require.Equal(t, m.client.maxRetries, uint8(1))
}
func TestOptions_DisableRetries(t *testing.T) {
meili := setup(t, "", DisableRetries())
require.NotNil(t, meili)
m, ok := meili.(*meilisearch)
require.True(t, ok)
require.Equal(t, m.client.disableRetry, true)
}