Use unique container names in tests

This commit improves test compatibility with real blobstores.
pull/16/head
Andrew Gaul 2014-08-18 17:09:15 -07:00
rodzic 02f68372e0
commit da512876de
1 zmienionych plików z 19 dodań i 7 usunięć

Wyświetl plik

@ -21,6 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.util.Properties; import java.util.Properties;
import java.util.Random;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -57,7 +58,7 @@ public final class S3ProxyTest {
private BlobStoreContext context; private BlobStoreContext context;
private BlobStoreContext s3Context; private BlobStoreContext s3Context;
private BlobStore s3BlobStore; private BlobStore s3BlobStore;
private static final String containerName = "container"; private String containerName;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
@ -99,6 +100,7 @@ public final class S3ProxyTest {
} }
context = builder.build(BlobStoreContext.class); context = builder.build(BlobStoreContext.class);
BlobStore blobStore = context.getBlobStore(); BlobStore blobStore = context.getBlobStore();
containerName = createRandomContainerName();
blobStore.createContainerInLocation(null, containerName); blobStore.createContainerInLocation(null, containerName);
Properties s3Properties = new Properties(); Properties s3Properties = new Properties();
@ -155,21 +157,27 @@ public final class S3ProxyTest {
for (StorageMetadata metadata : s3BlobStore.list()) { for (StorageMetadata metadata : s3BlobStore.list()) {
builder.add(metadata.getName()); builder.add(metadata.getName());
} }
assertThat(builder.build()).containsOnly(containerName); assertThat(builder.build()).contains(containerName);
} }
@Test @Test
public void testContainerExists() throws Exception { public void testContainerExists() throws Exception {
assertThat(s3BlobStore.containerExists("fakecontainer")).isFalse();
assertThat(s3BlobStore.containerExists(containerName)).isTrue(); assertThat(s3BlobStore.containerExists(containerName)).isTrue();
assertThat(s3BlobStore.containerExists(createRandomContainerName()))
.isFalse();
} }
@Test @Test
public void testContainerCreate() throws Exception { public void testContainerCreateDelete() throws Exception {
String containerName2 = createRandomContainerName();
assertThat(s3BlobStore.createContainerInLocation(null, assertThat(s3BlobStore.createContainerInLocation(null,
"newcontainer")).isTrue(); containerName2)).isTrue();
assertThat(s3BlobStore.createContainerInLocation(null, try {
"newcontainer")).isFalse(); assertThat(s3BlobStore.createContainerInLocation(null,
containerName2)).isFalse();
} finally {
s3BlobStore.deleteContainer(containerName2);
}
} }
@Test @Test
@ -319,4 +327,8 @@ public final class S3ProxyTest {
assertThat(getResponse.getStatusCode()) assertThat(getResponse.getStatusCode())
.isEqualTo(HttpServletResponse.SC_OK); .isEqualTo(HttpServletResponse.SC_OK);
} }
private static String createRandomContainerName() {
return "s3proxy-" + new Random().nextInt(Integer.MAX_VALUE);
}
} }