-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhosts_test.go
66 lines (57 loc) · 1.3 KB
/
hosts_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
package alldebrid
import (
"fmt"
"net/http"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
)
func TestClient_GetDomainsOnly(t *testing.T) {
getHostsEndpoint = func() string {
return "http://127.0.0.1"
}
tests := []struct {
name string
jsonResp string
statusResp int
c *Client
want Domains
assertion assert.ErrorAssertionFunc
}{
{
name: "bad json",
jsonResp: `{"status":"successful",}`,
statusResp: http.StatusOK,
c: cl,
assertion: assert.Error,
},
{
name: "status error",
jsonResp: `{"status":"error"}`,
statusResp: http.StatusOK,
c: cl,
assertion: assert.Error,
},
{
name: "status successful",
jsonResp: `{"status":"success"}`,
statusResp: http.StatusOK,
c: cl,
want: Domains{
Status: "success",
},
assertion: assert.NoError,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", fmt.Sprintf(hostsdomains, getHostsEndpoint(), tt.c.ic.appName),
httpmock.NewStringResponder(tt.statusResp, tt.jsonResp))
got, err := tt.c.GetDomainsOnly()
tt.assertion(t, err)
assert.Equal(t, tt.want, got)
})
}
}