Add and retrieve an attachment, including a subrange
(t *testing.T)
| 90 | |
| 91 | // Add and retrieve an attachment, including a subrange |
| 92 | func TestDocAttachment(t *testing.T) { |
| 93 | rt := NewRestTester(t, &RestTesterConfig{GuestEnabled: true}) |
| 94 | defer rt.Close() |
| 95 | |
| 96 | version := rt.PutDoc("doc", `{"prop":true}`) |
| 97 | |
| 98 | attachmentBody := "this is the body of attachment" |
| 99 | attachmentContentType := "content/type" |
| 100 | version = rt.storeAttachment("doc", version, "attach1", attachmentBody) |
| 101 | |
| 102 | // retrieve attachment |
| 103 | response := rt.SendRequest("GET", "/{{.keyspace}}/doc/attach1", "") |
| 104 | RequireStatus(t, response, 200) |
| 105 | assert.Equal(t, attachmentBody, response.Body.String()) |
| 106 | assert.Equal(t, "bytes", response.Header().Get("Accept-Ranges")) |
| 107 | assert.Equal(t, "", response.Header().Get("Content-Disposition")) |
| 108 | assert.Equal(t, "30", response.Header().Get("Content-Length")) |
| 109 | assert.Equal(t, attachmentContentType, response.Header().Get("Content-Type")) |
| 110 | |
| 111 | // retrieve subrange |
| 112 | response = rt.SendRequestWithHeaders("GET", "/{{.keyspace}}/doc/attach1", "", map[string]string{"Range": "bytes=5-6"}) |
| 113 | RequireStatus(t, response, 206) |
| 114 | assert.Equal(t, "is", response.Body.String()) |
| 115 | assert.Equal(t, "bytes", response.Header().Get("Accept-Ranges")) |
| 116 | assert.Equal(t, "2", response.Header().Get("Content-Length")) |
| 117 | assert.Equal(t, "bytes 5-6/30", response.Header().Get("Content-Range")) |
| 118 | assert.Equal(t, attachmentContentType, response.Header().Get("Content-Type")) |
| 119 | |
| 120 | // attempt to delete an attachment that is not on the document |
| 121 | response = rt.SendRequest("DELETE", "/{{.keyspace}}/doc/attach2?rev="+version.RevTreeID, "") |
| 122 | RequireStatus(t, response, 404) |
| 123 | |
| 124 | // attempt to delete attachment from non existing doc |
| 125 | response = rt.SendRequest("DELETE", "/{{.keyspace}}/doc1/attach1?rev=1-xzy", "") |
| 126 | RequireStatus(t, response, 404) |
| 127 | |
| 128 | // attempt to delete attachment using incorrect revid |
| 129 | response = rt.SendRequest("DELETE", "/{{.keyspace}}/doc/attach1?rev=1-xzy", "") |
| 130 | RequireStatus(t, response, 409) |
| 131 | |
| 132 | // delete the attachment calling the delete attachment endpoint |
| 133 | response = rt.SendRequest("DELETE", "/{{.keyspace}}/doc/attach1?rev="+version.RevTreeID, "") |
| 134 | RequireStatus(t, response, 200) |
| 135 | |
| 136 | // attempt to access deleted attachment (should return error) |
| 137 | response = rt.SendRequest("GET", "/{{.keyspace}}/doc/attach1", "") |
| 138 | RequireStatus(t, response, 404) |
| 139 | } |
| 140 | |
| 141 | func TestDocAttachmentMetaOption(t *testing.T) { |
| 142 | rt := NewRestTester(t, &RestTesterConfig{GuestEnabled: true}) |
nothing calls this directly
no test coverage detected