Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions sdk-tests/src/test/java/io/dapr/it/binding/http/BindingIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public void httpOutputBindingError() throws Exception {
client.invokeBinding("github-http-binding-404", "get", "").block();
fail("Should throw an exception");
} catch (DaprException e) {
assertEquals(404, e.getHttpStatusCode());
assertGitHubErrorStatus(e.getHttpStatusCode());
// This HTTP binding did not set `errorIfNot2XX` to false in component metadata, so the error payload is not
// consistent between HTTP and gRPC.
assertTrue(new String(e.getPayload()).contains(
"error invoking output binding github-http-binding-404: received status code 404"));
"error invoking output binding github-http-binding-404: received status code " + e.getHttpStatusCode()));
}
}, 10000);
}
Expand All @@ -78,18 +78,25 @@ public void httpOutputBindingErrorIgnoredByComponent() throws Exception {
client.invokeBinding("github-http-binding-404-success", "get", "").block();
fail("Should throw an exception");
} catch (DaprException e) {
assertEquals(404, e.getHttpStatusCode());
assertGitHubErrorStatus(e.getHttpStatusCode());
// The HTTP binding must set `errorIfNot2XX` to false in component metadata for the error payload to be
// consistent between HTTP and gRPC.
assertTrue(new String(e.getPayload()).contains("message"));
assertTrue(new String(e.getPayload()).contains("Not Found"));
assertTrue(new String(e.getPayload()).contains(
e.getHttpStatusCode() == 404 ? "Not Found" : "API rate limit exceeded"));
assertTrue(new String(e.getPayload()).contains("documentation_url"));
assertTrue(new String(e.getPayload()).contains("https://docs.github.com/rest"));
}
}, 10000);
}
}

// api.github.com answers 404 for an unknown path, or 403 when the runner's IP has used up the unauthenticated
// rate limit. Either way the binding must pass the status and body through.
private static void assertGitHubErrorStatus(int status) {
assertTrue(status == 404 || status == 403, "expected 404 or 403 but was " + status);
}

@Test
public void inputOutputBinding() throws Exception {
var bindingName = "sample123";
Expand Down
Loading