Skip to content

Commit 32ae8bb

Browse files
committed
test: more coverage
1 parent d0d5dd9 commit 32ae8bb

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

src/test/java/com/influxdb/v3/client/internal/RestClientTest.java

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,20 +740,22 @@ private static Stream<Arguments> errorFromBodyV3WithDataArrayCases() {
740740
@ParameterizedTest(name = "{0}")
741741
@MethodSource("errorFromBodyV3FallbackCases")
742742
public void errorFromBodyV3FallbackCase(final String testName,
743+
final String requestPath,
744+
final String contentType,
743745
final String body,
744746
final Class<? extends InfluxDBApiException> expectedClass,
745747
final String expectedMessage) {
746748

747749
mockServer.enqueue(createResponse(400,
748-
"application/json",
750+
contentType,
749751
null,
750752
body));
751753

752754
restClient = new RestClient(new ClientConfig.Builder()
753755
.host(baseURL)
754756
.build());
755757

756-
Throwable thrown = catchThrowable(() -> restClient.request("ping", HttpMethod.GET, null, null, null));
758+
Throwable thrown = catchThrowable(() -> restClient.request(requestPath, HttpMethod.GET, null, null, null));
757759
Assertions.assertThat(thrown)
758760
.isInstanceOf(expectedClass)
759761
.hasMessage(expectedMessage);
@@ -763,13 +765,17 @@ private static Stream<Arguments> errorFromBodyV3FallbackCases() {
763765
return Stream.of(
764766
Arguments.of(
765767
"missing error with data array falls back to body",
768+
"ping",
769+
"application/json",
766770
"{\"data\":[{\"error_message\":\"bad line\",\"line_number\":2,\"original_line\":\"bad lp\"}]}",
767771
InfluxDBApiHttpException.class,
768772
"HTTP status code: 400; Message: "
769773
+ "{\"data\":[{\"error_message\":\"bad line\",\"line_number\":2,\"original_line\":\"bad lp\"}]}"
770774
),
771775
Arguments.of(
772776
"empty error with data array falls back to body",
777+
"ping",
778+
"application/json",
773779
"{\"error\":\"\",\"data\":[{\"error_message\":\"bad line\",\"line_number\":2,\"original_line\":"
774780
+ "\"bad lp\"}]}",
775781
InfluxDBApiHttpException.class,
@@ -779,39 +785,95 @@ private static Stream<Arguments> errorFromBodyV3FallbackCases() {
779785
),
780786
Arguments.of(
781787
"data object without error_message falls back to error",
788+
"ping",
789+
"application/json",
782790
"{\"error\":\"parsing failed\",\"data\":{}}",
783791
InfluxDBApiHttpException.class,
784792
"HTTP status code: 400; Message: parsing failed"
785793
),
786794
Arguments.of(
787795
"data object with empty error_message falls back to error",
796+
"ping",
797+
"application/json",
788798
"{\"error\":\"parsing failed\",\"data\":{\"error_message\":\"\"}}",
789799
InfluxDBApiHttpException.class,
790800
"HTTP status code: 400; Message: parsing failed"
791801
),
792802
Arguments.of(
793803
"data string falls back to error",
804+
"ping",
805+
"application/json",
794806
"{\"error\":\"parsing failed\",\"data\":\"not-an-object\"}",
795807
InfluxDBApiHttpException.class,
796808
"HTTP status code: 400; Message: parsing failed"
797809
),
798810
Arguments.of(
799811
"data number falls back to error",
812+
"ping",
813+
"application/json",
800814
"{\"error\":\"parsing failed\",\"data\":123}",
801815
InfluxDBApiHttpException.class,
802816
"HTTP status code: 400; Message: parsing failed"
803817
),
804818
Arguments.of(
805819
"partial-write with invalid data string falls back to error",
820+
"ping",
821+
"application/json",
806822
"{\"error\":\"partial write of line protocol occurred\",\"data\":\"invalid\"}",
807823
InfluxDBApiHttpException.class,
808824
"HTTP status code: 400; Message: partial write of line protocol occurred"
809825
),
810826
Arguments.of(
811827
"partial-write with empty data object falls back to error",
828+
"ping",
829+
"application/json",
812830
"{\"error\":\"partial write of line protocol occurred\",\"data\":{}}",
813831
InfluxDBApiHttpException.class,
814832
"HTTP status code: 400; Message: partial write of line protocol occurred"
833+
),
834+
Arguments.of(
835+
"write endpoint ignores line-error parsing for non-json content type",
836+
"api/v3/write_lp",
837+
"text/plain",
838+
"{\"error\":\"partial write of line protocol occurred\",\"data\":[{\"error_message\":\"bad line\","
839+
+ "\"line_number\":2,\"original_line\":\"bad lp\"}]}",
840+
InfluxDBApiHttpException.class,
841+
"HTTP status code: 400; Message: "
842+
+ "{\"error\":\"partial write of line protocol occurred\",\"data\":[{\"error_message\":\"bad line\","
843+
+ "\"line_number\":2,\"original_line\":\"bad lp\"}]}"
844+
),
845+
Arguments.of(
846+
"write endpoint with non-object root falls back to body",
847+
"api/v3/write_lp",
848+
"application/json",
849+
"[]",
850+
InfluxDBApiHttpException.class,
851+
"HTTP status code: 400; Message: []"
852+
),
853+
Arguments.of(
854+
"write endpoint with invalid line-error object type falls back to http exception",
855+
"api/v3/write_lp",
856+
"application/json",
857+
"{\"error\":\"partial write of line protocol occurred\",\"data\":{\"error_message\":\"bad line\","
858+
+ "\"line_number\":{\"x\":2},\"original_line\":\"bad lp\"}}",
859+
InfluxDBApiHttpException.class,
860+
"HTTP status code: 400; Message: bad line"
861+
),
862+
Arguments.of(
863+
"write endpoint with scalar data falls back to error",
864+
"api/v3/write_lp",
865+
"application/json",
866+
"{\"error\":\"partial write of line protocol occurred\",\"data\":123}",
867+
InfluxDBApiHttpException.class,
868+
"HTTP status code: 400; Message: partial write of line protocol occurred"
869+
),
870+
Arguments.of(
871+
"write endpoint invalid json body falls back to raw body",
872+
"api/v3/write_lp",
873+
"application/json",
874+
"{\"error\":\"partial write of line protocol occurred\"",
875+
InfluxDBApiHttpException.class,
876+
"HTTP status code: 400; Message: {\"error\":\"partial write of line protocol occurred\""
815877
)
816878
);
817879
}

0 commit comments

Comments
 (0)