Skip to content

Commit e4795b6

Browse files
author
Dhriti Chopra
committed
test: Adding and Updating tests
1 parent 813dde8 commit e4795b6

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

google-cloud-storage/src/test/java/com/google/cloud/storage/ChecksumResponseParserTest.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void testParse() throws IOException {
4343

4444
assertThat(uploadPartResponse.eTag()).isEqualTo("\"test-etag\"");
4545
assertThat(uploadPartResponse.md5()).isEqualTo("rL0Y20zC+Fzt72VPzMSk2A==");
46+
assertThat(uploadPartResponse.crc32c()).isEqualTo("AAAAAA==");
4647
}
4748

4849
@Test
@@ -85,13 +86,34 @@ public void testExtractHashesFromHeader_emptyHeader() throws IOException {
8586
assertThat(hashes).isEmpty();
8687
}
8788

88-
private HttpResponse createHttpResponse(String etag, String googHash) throws IOException {
89+
@Test
90+
public void testExtractHashesFromHeader_multipleHeaders() throws IOException {
91+
HttpResponse response =
92+
createHttpResponse(null, "crc32c=AAAAAA==", "md5=rL0Y20zC+Fzt72VPzMSk2A==");
93+
Map<String, String> hashes = ChecksumResponseParser.extractHashesFromHeader(response);
94+
assertThat(hashes).containsEntry("crc32c", "AAAAAA==");
95+
assertThat(hashes).containsEntry("md5", "rL0Y20zC+Fzt72VPzMSk2A==");
96+
}
97+
98+
@Test
99+
public void testExtractHashesFromHeader_multipleHeadersAndCsv() throws IOException {
100+
HttpResponse response =
101+
createHttpResponse(null, "crc32c=AAAAAA==", "md5=rL0Y20zC+Fzt72VPzMSk2A==,extra=value");
102+
Map<String, String> hashes = ChecksumResponseParser.extractHashesFromHeader(response);
103+
assertThat(hashes).containsEntry("crc32c", "AAAAAA==");
104+
assertThat(hashes).containsEntry("md5", "rL0Y20zC+Fzt72VPzMSk2A==");
105+
assertThat(hashes).hasSize(2);
106+
}
107+
108+
private HttpResponse createHttpResponse(String etag, String... googHash) throws IOException {
89109
MockLowLevelHttpResponse lowLevelResponse = new MockLowLevelHttpResponse();
90110
if (etag != null) {
91111
lowLevelResponse.addHeader("ETag", etag);
92112
}
93113
if (googHash != null) {
94-
lowLevelResponse.addHeader("x-goog-hash", googHash);
114+
for (String hash : googHash) {
115+
lowLevelResponse.addHeader("x-goog-hash", hash);
116+
}
95117
}
96118
HttpTransport transport =
97119
new MockHttpTransport.Builder().setLowLevelHttpResponse(lowLevelResponse).build();

0 commit comments

Comments
 (0)