Skip to content

Commit

Permalink
Add test for mime types set on blobs
Browse files Browse the repository at this point in the history
  • Loading branch information
janhicken committed May 1, 2024
1 parent 2451cb5 commit 74efb78
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.janhicken.maven.wagon.gs;

import com.google.api.services.storage.model.StorageObject;
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.StorageOptions;
import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper;
import com.google.cloud.storage.spi.v1.StorageRpc;
Expand All @@ -12,12 +13,15 @@

public class GSWagonTest extends StreamingWagonTestCase {

protected static final String BUCKET_NAME = "test-bucket";
protected static final String PREFIX = "repo";

final StorageOptions storageOptions = LocalStorageHelper.getOptions();
final GSWagon wagon = new GSWagon(storageOptions);

@Override
protected String getTestRepositoryUrl() {
return "gs://test-bucket/repo";
return BlobId.of(BUCKET_NAME, PREFIX).toGsUtilUri();
}

@Override
Expand Down Expand Up @@ -49,4 +53,30 @@ public void testLookupByProtocol() throws Exception {
String.format("Expected an instance of GSWagon, got: %s", result.getClass().getName()),
result instanceof GSWagon);
}

public void testMimeType() throws Exception {
final var rpc = (StorageRpc) storageOptions.getRpc();
setupWagonTestingFixtures();
setupRepositories();

final var expectedMimeTypes =
Map.of(
"jar", "application/java-archive",
"pom", "application/xml",
"asc", "text/plain",
"sha1", "text/plain");
for (final var expectedMimeType : expectedMimeTypes.entrySet()) {
final var resourceName = "mime_test." + expectedMimeType.getKey();
putFile(resourceName, resourceName, "foo");

final var storageObject = new StorageObject();
storageObject.setBucket(BUCKET_NAME);
storageObject.setName(PREFIX + '/' + resourceName);
final var ret = rpc.get(storageObject, Map.of());
assertEquals(
"Unexpected content type for " + resourceName,
expectedMimeType.getValue(),
ret.getContentType());
}
}
}

0 comments on commit 74efb78

Please sign in to comment.