Skip to content

Commit

Permalink
Merge pull request apache#6 from steffenrost/sr-does-db-exist
Browse files Browse the repository at this point in the history
Make sure database is deleted in tests to avoid error on create
  • Loading branch information
steffenrost committed Mar 10, 2020
2 parents c2ffe91 + 4016b28 commit 3fe98d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ trait DatabaseScriptTestUtils extends ScalaFutures with Matchers with WaitFor wi
val delete = db.deleteDb().futureValue
if (!ignoreFailure) delete shouldBe 'right
}
// make sure database is deleted
retry {
val exist = db.doesDbExist().futureValue
exist shouldBe false
}
db
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ class ExtendedCouchDbRestClient(protocol: String,
def deleteDb(): Future[Either[StatusCode, JsObject]] =
requestJson[JsObject](mkRequest(HttpMethods.DELETE, uri(db), headers = baseHeaders))

// http://docs.couchdb.org/en/1.6.1/api/database/common.html#head--db
def doesDbExist(): Future[Boolean] = {
requestJson[JsObject](mkRequest(HttpMethods.HEAD, uri(db), headers = baseHeaders))
.map {
case Right(_) => true
case Left(StatusCodes.NotFound) => false
case Left(s) => throw new IllegalStateException("Unknown status code while checking db:" + s)
}
}

// http://docs.couchdb.org/en/1.6.1/api/database/bulk-api.html#get--db-_all_docs
def getAllDocs(skip: Option[Int] = None,
limit: Option[Int] = None,
Expand Down

0 comments on commit 3fe98d9

Please sign in to comment.