MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestBytesReadDocOperations

Function TestBytesReadDocOperations

rest/bytes_read_public_api_test.go:26–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestBytesReadDocOperations(t *testing.T) {
27 rt := NewRestTester(t, &RestTesterConfig{SyncFn: channels.DocChannelsSyncFunction})
28 defer rt.Close()
29
30 // create a user to authenticate as for public api calls and assert the stat hasn't incremented as a result
31 rt.CreateUser("greg", []string{"ABC"})
32 base.RequireWaitForStat(t, func() int64 {
33 return rt.GetDatabase().DbStats.DatabaseStats.PublicRestBytesRead.Value()
34 }, 0)
35
36 // use public api to put a doc through SGW then assert the stat has increased
37 input := `{"foo":"bar", "channels":["ABC"]}`
38 inputBytes := []byte(input)
39 resp := rt.SendUserRequest(http.MethodPut, "/{{.keyspace}}/doc1", input, "greg")
40 RequireStatus(t, resp, http.StatusCreated)
41
42 base.RequireWaitForStat(t, func() int64 {
43 return rt.GetDatabase().DbStats.DatabaseStats.PublicRestBytesRead.Value()
44 }, int64(len(inputBytes)))
45
46 // send admin request assert that the public rest count doesn't increase
47 resp = rt.SendAdminRequest(http.MethodGet, "/{{.keyspace}}/doc1", "")
48 RequireStatus(t, resp, http.StatusOK)
49 base.RequireWaitForStat(t, func() int64 {
50 return rt.GetDatabase().DbStats.DatabaseStats.PublicRestBytesRead.Value()
51 }, int64(len(inputBytes)))
52
53 // send user request that has empty body, assert the stat doesn't increase
54 resp = rt.SendUserRequest(http.MethodGet, "/{{.keyspace}}/doc1", "", "greg")
55 RequireStatus(t, resp, http.StatusOK)
56 base.RequireWaitForStat(t, func() int64 {
57 return rt.GetDatabase().DbStats.DatabaseStats.PublicRestBytesRead.Value()
58 }, int64(len(inputBytes)))
59
60 // assert blipsync connection doesn't increment stat
61 resp = rt.SendUserRequest(http.MethodGet, "/{{.db}}/_blipsync", "", "greg")
62 RequireStatus(t, resp, http.StatusUpgradeRequired)
63 base.RequireWaitForStat(t, func() int64 {
64 return rt.GetDatabase().DbStats.DatabaseStats.PublicRestBytesRead.Value()
65 }, int64(len(inputBytes)))
66
67 srv := httptest.NewServer(rt.TestMetricsHandler())
68 defer srv.Close()
69
70 // test metrics endpoint, assert the stat doesn't increment
71 response, err := http.Get(srv.URL + "/_metrics")
72 require.NoError(t, err)
73 assert.Equal(t, http.StatusOK, response.StatusCode)
74 require.NoError(t, response.Body.Close())
75
76 base.RequireWaitForStat(t, func() int64 {
77 return rt.GetDatabase().DbStats.DatabaseStats.PublicRestBytesRead.Value()
78 }, int64(len(inputBytes)))
79
80 // test public endpoint but one that doesn't access a db and assert that doesn't increment stat
81 resp = rt.SendUserRequest(http.MethodGet, "/", "", "greg")
82 RequireStatus(t, resp, http.StatusOK)
83 // assert the stat doesn't increment

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
CreateUserMethod · 0.95
GetDatabaseMethod · 0.95
SendUserRequestMethod · 0.95
SendAdminRequestMethod · 0.95
TestMetricsHandlerMethod · 0.95
RequireWaitForStatFunction · 0.92
NewRestTesterFunction · 0.85
RequireStatusFunction · 0.85
CloseMethod · 0.65
ValueMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected