WaitForVersion retries a GET for a given document version until it returns 200 or 201 for a given document and revision. If version is not found, the test will fail.
(docID string, version DocVersion)
| 209 | |
| 210 | // WaitForVersion retries a GET for a given document version until it returns 200 or 201 for a given document and revision. If version is not found, the test will fail. |
| 211 | func (rt *RestTester) WaitForVersion(docID string, version DocVersion) { |
| 212 | if version.RevTreeID == "" { |
| 213 | require.NotEqual(rt.TB(), "", version.CV.String(), "Expected CV if RevTreeID is empty for version %#v in WaitForVersion", version) |
| 214 | } |
| 215 | require.EventuallyWithT(rt.TB(), func(c *assert.CollectT) { |
| 216 | rawResponse := rt.SendAdminRequest("GET", "/{{.keyspace}}/"+docID, "") |
| 217 | if !assert.Contains(c, []int{200, 201}, rawResponse.Code, "Unexpected status code for %s", rawResponse.Body.String()) { |
| 218 | return |
| 219 | } |
| 220 | var body db.Body |
| 221 | require.NoError(rt.TB(), base.JSONUnmarshal(rawResponse.Body.Bytes(), &body)) |
| 222 | if version.RevTreeID != "" { |
| 223 | assert.Equal(c, version.RevTreeID, body.ExtractRev()) |
| 224 | } |
| 225 | if version.CV.IsEmpty() { |
| 226 | return |
| 227 | } |
| 228 | if !assert.Contains(c, body, db.BodyCV) { |
| 229 | return |
| 230 | } |
| 231 | assert.Equal(c, version.CV.String(), body[db.BodyCV].(string)) |
| 232 | }, 10*time.Second, 50*time.Millisecond) |
| 233 | } |
| 234 | |
| 235 | func (rt *RestTester) WaitForVersionRevIDOnly(docID string, version DocVersion) { |
| 236 | version.CV = db.Version{} // empty cv so WaitForVersion only asserts on revID |