Skip to content

Commit

Permalink
refactor test logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-munro committed Nov 7, 2024
1 parent fc51962 commit 8f5f8d8
Showing 1 changed file with 10 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,8 @@ public void runCreateBucket() {
String bucket = "random-bucket";
storage.create(BucketInfo.of(bucket));
TestExporter testExported = (TestExporter) exporter;
SpanData spanData = testExported.getExportedSpans().get(0);
Assert.assertEquals("Storage", getAttributeValue(spanData, "gcp.client.service"));
Assert.assertEquals("googleapis/java-storage", getAttributeValue(spanData, "gcp.client.repo"));
Assert.assertEquals(
"com.google.cloud.google-cloud-storage",
getAttributeValue(spanData, "gcp.client.artifact"));
Assert.assertEquals("http", getAttributeValue(spanData, "rpc.system"));
List<SpanData> spanData = testExported.getExportedSpans();
checkCommonAttributes(spanData);
}

@Test
Expand All @@ -100,13 +95,7 @@ public void runCreateBlob() {
storage.create(BlobInfo.newBuilder(toCreate).build(), content);
TestExporter testExported = (TestExporter) exporter;
List<SpanData> spanData = testExported.getExportedSpans();
for (SpanData span : spanData) {
Assert.assertEquals("Storage", getAttributeValue(span, "gcp.client.service"));
Assert.assertEquals("googleapis/java-storage", getAttributeValue(span, "gcp.client.repo"));
Assert.assertEquals(
"com.google.cloud.google-cloud-storage", getAttributeValue(span, "gcp.client.artifact"));
Assert.assertEquals("http", getAttributeValue(span, "rpc.system"));
}
checkCommonAttributes(spanData);
}

@Test
Expand All @@ -119,13 +108,7 @@ public void runRead() throws IOException {
blobId, helloWorldTxtGz, Storage.BlobSourceOption.shouldReturnRawInputStream(true));
TestExporter testExported = (TestExporter) exporter;
List<SpanData> spanData = testExported.getExportedSpans();
for (SpanData span : spanData) {
Assert.assertEquals("Storage", getAttributeValue(span, "gcp.client.service"));
Assert.assertEquals("googleapis/java-storage", getAttributeValue(span, "gcp.client.repo"));
Assert.assertEquals(
"com.google.cloud.google-cloud-storage", getAttributeValue(span, "gcp.client.artifact"));
Assert.assertEquals("http", getAttributeValue(span, "rpc.system"));
}
checkCommonAttributes(spanData);
Assert.assertTrue(spanData.stream().anyMatch(x -> x.getName().contains("read")));
}

Expand All @@ -149,20 +132,23 @@ public void runCopy() {
.setSourceOptions(BlobSourceOption.generationMatch(cpySrc.getGeneration()))
.setTarget(dst, BlobTargetOption.doesNotExist())
.build();

CopyWriter copyWriter = storage.copy(copyRequest);
copyWriter.getResult();
TestExporter testExported = (TestExporter) exporter;
List<SpanData> spanData = testExported.getExportedSpans();
checkCommonAttributes(spanData);
Assert.assertTrue(spanData.stream().anyMatch(x -> x.getName().contains("openRewrite")));
Assert.assertTrue(spanData.stream().anyMatch(x -> x.getName().contains("rewrite")));
}

private void checkCommonAttributes(List<SpanData> spanData) {
for (SpanData span : spanData) {
Assert.assertEquals("Storage", getAttributeValue(span, "gcp.client.service"));
Assert.assertEquals("googleapis/java-storage", getAttributeValue(span, "gcp.client.repo"));
Assert.assertEquals(
"com.google.cloud.google-cloud-storage", getAttributeValue(span, "gcp.client.artifact"));
Assert.assertEquals("http", getAttributeValue(span, "rpc.system"));
}
Assert.assertTrue(spanData.stream().anyMatch(x -> x.getName().contains("openRewrite")));
Assert.assertTrue(spanData.stream().anyMatch(x -> x.getName().contains("rewrite")));
}

private String getAttributeValue(SpanData spanData, String key) {
Expand Down

0 comments on commit 8f5f8d8

Please sign in to comment.