Skip to content

Commit 84832af

Browse files
Fix tests exitcode and v2 response handling (#501)
1 parent a312b05 commit 84832af

File tree

5 files changed

+28
-85
lines changed

5 files changed

+28
-85
lines changed

Makefile

+14-10
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,13 @@ __test_go_test:
393393
-e GODEBUG=tls13=1 \
394394
-e CGO_ENABLED=$(CGO_ENABLED) \
395395
-w /usr/code/ \
396-
$(DOCKER_RUN_CMD) && echo "success!" || \
397-
{ echo "failure! \n\nARANGODB-STARTER logs:"; docker logs ${TESTCONTAINER}-s; \
398-
echo "\nARANGODB logs:"; docker ps -f name=${TESTCONTAINER}-s- -q | xargs -L 1 docker logs; \
399-
echo "\nV1 Tests with ARGS: TEST_MODE=${TEST_MODE} TEST_AUTH=${TEST_AUTH} TEST_CONTENT_TYPE=${TEST_CONTENT_TYPE} TEST_SSL=${TEST_SSL} TEST_CONNECTION=${TEST_CONNECTION} TEST_CVERSION=${TEST_CVERSION}\n\n" \
400-
exit 1; }
396+
$(DOCKER_RUN_CMD) && echo "success!" || ( \
397+
echo "failure! \n\nARANGODB-STARTER logs:"; \
398+
docker logs ${TESTCONTAINER}-s; \
399+
echo "\nARANGODB logs:"; \
400+
docker ps -f name=${TESTCONTAINER}-s- -q | xargs -L 1 docker logs; \
401+
echo "\nV1 Tests with ARGS: TEST_MODE=${TEST_MODE} TEST_AUTH=${TEST_AUTH} TEST_CONTENT_TYPE=${TEST_CONTENT_TYPE} TEST_SSL=${TEST_SSL} TEST_CONNECTION=${TEST_CONNECTION} TEST_CVERSION=${TEST_CVERSION}\n\n"; \
402+
exit 1)
401403
# Internal test tasks
402404
__run_v2_tests: __test_v2_debug__ __test_prepare __test_v2_go_test __test_cleanup
403405

@@ -418,11 +420,13 @@ __test_v2_go_test:
418420
-e GODEBUG=tls13=1 \
419421
-e CGO_ENABLED=$(CGO_ENABLED) \
420422
-w /usr/code/v2/ \
421-
$(DOCKER_V2_RUN_CMD) && echo "success!" || \
422-
{ echo "failure! \n\nARANGODB-STARTER logs:"; docker logs ${TESTCONTAINER}-s; \
423-
echo "\nARANGODB logs:"; docker ps -f name=${TESTCONTAINER}-s- -q | xargs -L 1 docker logs; \
424-
echo "\nV2 Tests with ARGS: TEST_MODE=${TEST_MODE} TEST_AUTH=${TEST_AUTH} TEST_CONTENT_TYPE=${TEST_CONTENT_TYPE} TEST_SSL=${TEST_SSL} TEST_CONNECTION=${TEST_CONNECTION} TEST_CVERSION=${TEST_CVERSION}\n\n" \
425-
exit 1; }
423+
$(DOCKER_V2_RUN_CMD) && echo "success!" || ( \
424+
echo "failure! \n\nARANGODB-STARTER logs:"; \
425+
docker logs ${TESTCONTAINER}-s; \
426+
echo "\nARANGODB logs:"; \
427+
docker ps -f name=${TESTCONTAINER}-s- -q | xargs -L 1 docker logs; \
428+
echo "\nV2 Tests with ARGS: TEST_MODE=${TEST_MODE} TEST_AUTH=${TEST_AUTH} TEST_CONTENT_TYPE=${TEST_CONTENT_TYPE} TEST_SSL=${TEST_SSL} TEST_CONNECTION=${TEST_CONNECTION} TEST_CVERSION=${TEST_CVERSION}\n\n"; \
429+
exit 1)
426430

427431
__test_debug__:
428432
ifeq ("$(DEBUG)", "true")

v2/connection/connection_http_internal.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (j httpConnection) Do(ctx context.Context, request Request, output interfac
175175
// The output should be stored in the output variable.
176176
if err = j.Decoder(resp.Content()).Decode(body, output); err != nil {
177177
if err != io.EOF {
178-
return nil, errors.WithStack(err)
178+
return resp, errors.WithStack(err)
179179
}
180180
}
181181
}
@@ -219,14 +219,7 @@ func (j httpConnection) stream(ctx context.Context, req *httpRequest) (*httpResp
219219
ctx = context.Background()
220220
}
221221

222-
ct := j.contentType
223-
224-
// for JWT auth requests we always use JSON
225-
if _, isJWT := req.body.(jwtOpenRequest); isJWT {
226-
ct = ApplicationJSON
227-
}
228-
229-
reader := j.bodyReadFunc(j.Decoder(ct), req.body, j.streamSender)
222+
reader := j.bodyReadFunc(j.Decoder(j.contentType), req.body, j.streamSender)
230223
r, err := req.asRequest(ctx, reader)
231224
if err != nil {
232225
return nil, nil, errors.WithStack(err)

v2/connection/connection_with_reauthentication.go

-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ type wrapAuthentication struct {
5252
func (w wrapAuthentication) Do(ctx context.Context, request Request, output interface{}) (Response, error) {
5353
r, err := w.Connection.Do(ctx, request, output)
5454

55-
if err != nil {
56-
return nil, err
57-
}
58-
5955
if r.Code() != http.StatusUnauthorized {
6056
return r, err
6157
}

v2/tests/decoder_test.go

+12-35
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,16 @@ import (
3131
"github.com/arangodb/go-driver/v2/connection"
3232
)
3333

34-
// Test_DecoderBytesWithJSONConnection gets plain text response from the server using JSON connection.
35-
func Test_DecoderBytesWithJSONConnection(t *testing.T) {
36-
conn := connectionJsonHttp(t)
37-
waitForConnection(t, arangodb.NewClient(conn))
38-
39-
var output []byte
40-
41-
url := connection.NewUrl("_admin", "metrics", "v2")
42-
_, err := connection.CallGet(context.Background(), conn, url, &output)
43-
require.NoError(t, err)
44-
require.NotNil(t, output)
45-
// Check the e
46-
assert.Contains(t, string(output), "arangodb_connection_pool")
47-
output = nil
48-
}
49-
50-
// Test_DecoderBytesWithPlainConnection gets plain text response from the server using plain connection.
51-
func Test_DecoderBytesWithPlainConnection(t *testing.T) {
52-
conn := connectionPlainHttp(t)
53-
client := newClient(t, conn)
54-
55-
// Check if the JSON deserializer worked.
56-
version, err := client.Version(context.Background())
57-
require.NoErrorf(t, err, "can not fetch a version with a plain connection: `%v`", err)
58-
require.Equalf(t, true, version.Version.Major() > 0, "can not fetch a version with a plain connection")
59-
60-
var output []byte
61-
62-
url := connection.NewUrl("_admin", "metrics", "v2")
63-
_, err = connection.CallGet(context.Background(), conn, url, &output)
64-
require.NoError(t, err)
65-
require.NotNil(t, output)
66-
// Check the e
67-
assert.Contains(t, string(output), "arangodb_connection_pool")
68-
output = nil
34+
// Test_DecoderBytes gets plain text response from the server
35+
func Test_DecoderBytes(t *testing.T) {
36+
Wrap(t, func(t *testing.T, client arangodb.Client) {
37+
var output []byte
38+
39+
url := connection.NewUrl("_admin", "metrics", "v2")
40+
_, err := connection.CallGet(context.Background(), client.Connection(), url, &output)
41+
42+
require.NoError(t, err)
43+
require.NotNil(t, output)
44+
assert.Contains(t, string(output), "arangodb_connection_pool")
45+
})
6946
}

v2/tests/run_wrap_test.go

-27
Original file line numberDiff line numberDiff line change
@@ -198,33 +198,6 @@ func connectionJsonHttp(t testing.TB) connection.Connection {
198198
return c
199199
}
200200

201-
func connectionPlainHttp(t testing.TB) connection.Connection {
202-
h := connection.HttpConfiguration{
203-
Endpoint: connection.NewEndpoints(getEndpointsFromEnv(t)...),
204-
ContentType: connection.PlainText,
205-
Transport: &http.Transport{
206-
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
207-
DialContext: (&net.Dialer{
208-
Timeout: 30 * time.Second,
209-
KeepAlive: 90 * time.Second,
210-
DualStack: true,
211-
}).DialContext,
212-
MaxIdleConns: 100,
213-
IdleConnTimeout: 90 * time.Second,
214-
TLSHandshakeTimeout: 10 * time.Second,
215-
ExpectContinueTimeout: 1 * time.Second,
216-
},
217-
}
218-
219-
c := connection.NewHttpConnection(h)
220-
221-
withContext(2*time.Minute, func(ctx context.Context) error {
222-
c = createAuthenticationFromEnv(t, c)
223-
return nil
224-
})
225-
return c
226-
}
227-
228201
func connectionVPACKHttp(t testing.TB) connection.Connection {
229202
h := connection.HttpConfiguration{
230203
Endpoint: connection.NewEndpoints(getEndpointsFromEnv(t)...),

0 commit comments

Comments
 (0)