-
Notifications
You must be signed in to change notification settings - Fork 0
/
organization_test.go
97 lines (83 loc) · 2.72 KB
/
organization_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package redash_test
import (
"context"
"net/http"
"testing"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/winebarrel/redash-go/v2"
)
func Test_GetOrganizationStatus_OK(t *testing.T) {
assert := assert.New(t)
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder(http.MethodGet, "https://redash.example.com/api/organization/status", func(req *http.Request) (*http.Response, error) {
assert.Equal(
http.Header(
http.Header{
"Authorization": []string{"Key " + testRedashAPIKey},
"Content-Type": []string{"application/json"},
"User-Agent": []string{"redash-go"},
},
),
req.Header,
)
return httpmock.NewStringResponse(http.StatusOK, `
{
"object_counters": {
"alerts": 1,
"dashboards": 2,
"data_sources": 3,
"queries": 4,
"users": 5
}
}
`), nil
})
client, _ := redash.NewClient("https://redash.example.com", testRedashAPIKey)
res, err := client.GetOrganizationStatus(context.Background())
assert.NoError(err)
assert.Equal(&redash.OrganizationStatus{
ObjectCounters: redash.OrganizationStatusObjectCounters{
Alerts: 1,
Dashboards: 2,
DataSources: 3,
Queries: 4,
Users: 5,
},
}, res)
}
func Test_GetOrganizationStatus_Err_5xx(t *testing.T) {
assert := assert.New(t)
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder(http.MethodGet, "https://redash.example.com/api/organization/status", func(req *http.Request) (*http.Response, error) {
return httpmock.NewStringResponse(http.StatusServiceUnavailable, "error"), nil
})
client, _ := redash.NewClient("https://redash.example.com", testRedashAPIKey)
_, err := client.GetOrganizationStatus(context.Background())
assert.ErrorContains(err, "GET api/organization/status failed: HTTP status code not OK: 503\nerror")
}
func Test_GetOrganizationStatus_IOErr(t *testing.T) {
assert := assert.New(t)
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder(http.MethodGet, "https://redash.example.com/api/organization/status", func(req *http.Request) (*http.Response, error) {
return testIOErrResp, nil
})
client, _ := redash.NewClient("https://redash.example.com", testRedashAPIKey)
_, err := client.GetOrganizationStatus(context.Background())
assert.ErrorContains(err, "Read response body failed: IO error")
}
func Test_GetOrganizationStatus_Acc(t *testing.T) {
if !testAcc {
t.Skip()
}
assert := assert.New(t)
require := require.New(t)
client, _ := redash.NewClient(testRedashEndpoint, testRedashAPIKey)
status, err := client.GetOrganizationStatus(context.Background())
require.NoError(err)
assert.NotNil(status)
}