Skip to content

Commit

Permalink
Makes sure that each test is run in a clean state 馃Ш
Browse files Browse the repository at this point in the history
The tests currently sometimes leave stuff behind, possibly influencing other tests.

#233
  • Loading branch information
jakobvogel committed Sep 18, 2023
1 parent ba8e16a commit ce1e173
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/test/java/BaseAWSSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ abstract class BaseAWSSpec extends BaseSpecification {
client.putObject(bucketName, key, new ByteArrayInputStream(data), metadata)
}

/**
* Before each test, delete all buckets and their objects. This allows to run the test based on a clean state.
*/
def setup() {
def client = getClient()

client.listBuckets().stream().forEach {
def bucket = it
client.listObjects(bucket.getName()).getObjectSummaries().stream().forEach {
client.deleteObject(bucket.getName(), it.getKey())
}
client.deleteBucket(bucket.getName())
}
}

/**
* After each test, make sure that the test leaves the state clean. This makes sure that no unintended side effects
* have been missed.
*/
def cleanup() {
def client = getClient()
if (!client.listBuckets().isEmpty()) {
throw new IllegalStateException("Test left state polluted. Ensure that the test includes a proper cleanup section.")
}
}

def "HEAD of non-existing bucket as expected"() {
given:
def bucketName = "does-not-exist"
Expand Down

0 comments on commit ce1e173

Please sign in to comment.