(t *testing.T)
| 122 | } |
| 123 | |
| 124 | func TestBytesReadPutAttachment(t *testing.T) { |
| 125 | rt := NewRestTester(t, &RestTesterConfig{SyncFn: channels.DocChannelsSyncFunction}) |
| 126 | defer rt.Close() |
| 127 | |
| 128 | // create user |
| 129 | rt.CreateUser("alice", []string{"ABC"}) |
| 130 | |
| 131 | // add a doc for an attachment to be added to |
| 132 | resp := rt.SendAdminRequest(http.MethodPut, fmt.Sprintf("/%s/%s", rt.GetSingleKeyspace(), "doc1"), `{"channels":["ABC"]}`) |
| 133 | RequireStatus(t, resp, http.StatusCreated) |
| 134 | var body db.Body |
| 135 | require.NoError(t, base.JSONUnmarshal(resp.Body.Bytes(), &body)) |
| 136 | require.Equal(t, true, body["ok"]) |
| 137 | revid := body["rev"].(string) |
| 138 | |
| 139 | resp = rt.SendUserRequest(http.MethodGet, fmt.Sprintf("/%s/%s", rt.GetSingleKeyspace(), "doc1"), ``, "alice") |
| 140 | RequireStatus(t, resp, http.StatusOK) |
| 141 | |
| 142 | attachmentBody := "this is the body of attachment" |
| 143 | attachmentContentType := "content/type" |
| 144 | reqHeaders := map[string]string{ |
| 145 | "Content-Type": attachmentContentType, |
| 146 | } |
| 147 | byteArrayAttachmentBody := []byte(attachmentBody) |
| 148 | |
| 149 | // attach to existing document created above |
| 150 | resp = rt.SendUserRequestWithHeaders("PUT", "/{{.keyspace}}/doc1/attach1?rev="+revid, attachmentBody, reqHeaders, "alice", "letmein") |
| 151 | RequireStatus(t, resp, http.StatusCreated) |
| 152 | |
| 153 | // assert the stat has increased by the attachment endpoint input |
| 154 | base.RequireWaitForStat(t, func() int64 { |
| 155 | return rt.GetDatabase().DbStats.DatabaseStats.PublicRestBytesRead.Value() |
| 156 | }, int64(len(byteArrayAttachmentBody))) |
| 157 | |
| 158 | // test incorrect user still increments count |
| 159 | resp = rt.SendUserRequestWithHeaders("PUT", "/{{.keyspace}}/doc1/attach1?rev="+revid, attachmentBody, reqHeaders, "bob", "letmein") |
| 160 | RequireStatus(t, resp, http.StatusUnauthorized) |
| 161 | |
| 162 | newStatNum := len(byteArrayAttachmentBody) * 2 |
| 163 | |
| 164 | base.RequireWaitForStat(t, func() int64 { |
| 165 | return rt.GetDatabase().DbStats.DatabaseStats.PublicRestBytesRead.Value() |
| 166 | }, int64(newStatNum)) |
| 167 | |
| 168 | } |
| 169 | |
| 170 | func TestBytesReadRevDiff(t *testing.T) { |
| 171 | rt := NewRestTester(t, nil) |
nothing calls this directly
no test coverage detected