Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 5 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@ language: go
env:
- TEST_SUITE=run-unit-tests GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch ALWAYS=1
- TEST_SUITE=run-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb:3.6
- TEST_SUITE=run-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb/arangodb:latest ALWAYS=1
- TEST_SUITE=run-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb:3.7
- TEST_SUITE=run-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb/arangodb-preview:3.8.0-nightly
- TEST_SUITE=run-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb/arangodb-preview:3.9.0-nightly
- TEST_SUITE=run-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb/arangodb-preview:latest
- TEST_SUITE=run-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb:3.8
- TEST_SUITE=run-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb/arangodb:latest ALWAYS=1
- TEST_SUITE=run-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb/arangodb-preview:latest TEST_DISALLOW_UNKNOWN_FIELDS=false
- TEST_SUITE=run-v2-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb:3.6
- TEST_SUITE=run-v2-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb/arangodb:latest ALWAYS=1
- TEST_SUITE=run-v2-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb:3.7
- TEST_SUITE=run-v2-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb/arangodb-preview:3.8.0-nightly
- TEST_SUITE=run-v2-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb/arangodb-preview:3.9.0-nightly
- TEST_SUITE=run-v2-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb:3.8
- TEST_SUITE=run-v2-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb/arangodb:latest ALWAYS=1
- TEST_SUITE=run-v2-tests-single GOIMAGE=gcr.io/gcr-for-testing/golang:1.16.6-stretch STARTER=gcr.io/gcr-for-testing/arangodb/arangodb-starter:latest ALPINE_IMAGE=gcr.io/gcr-for-testing/alpine:3.4 ARANGODB=gcr.io/gcr-for-testing/arangodb/arangodb-preview:latest

script:
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ __test_go_test:
-e TEST_DEBUG='$(TEST_DEBUG)' \
-e TEST_ENABLE_SHUTDOWN=$(TEST_ENABLE_SHUTDOWN) \
-e TEST_REQUEST_LOG=$(TEST_REQUEST_LOG) \
-e TEST_DISALLOW_UNKNOWN_FIELDS=$(TEST_DISALLOW_UNKNOWN_FIELDS) \
-e GODEBUG=tls13=1 \
-e CGO_ENABLED=$(CGO_ENABLED) \
-w /usr/code/ \
Expand Down
91 changes: 91 additions & 0 deletions http/connection_wrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package http

import (
"context"
"encoding/json"
"errors"
"fmt"
"reflect"
"strings"

"github.com/arangodb/go-driver"
"github.com/arangodb/go-velocypack"
)

type connectionDebugWrapper struct {
driver.Connection
ct driver.ContentType
}

func NewConnectionDebugWrapper(conn driver.Connection, ct driver.ContentType) driver.Connection {
return &connectionDebugWrapper{conn, ct}
}

func (c *connectionDebugWrapper) Do(ctx context.Context, req driver.Request) (driver.Response, error) {
if c.ct == driver.ContentTypeJSON {
resp, err := c.Connection.Do(ctx, req)
if err != nil {
return resp, err
}

httpResponse, ok := resp.(*httpJSONResponse)
if !ok {
panic("can not cast response to the httpJSONResponse type!")
}

return &responseDebugWrapper{httpResponse}, err

}
return c.Connection.Do(ctx, req)
}

func (c *connectionDebugWrapper) Unmarshal(data driver.RawObject, result interface{}) error {
ct := c.ct
if ct == driver.ContentTypeVelocypack && len(data) >= 2 {
// Poor mans auto detection of json
l := len(data)
if (data[0] == '{' && data[l-1] == '}') || (data[0] == '[' && data[l-1] == ']') {
ct = driver.ContentTypeJSON
}
}
switch ct {
case driver.ContentTypeJSON:
decoder := json.NewDecoder(strings.NewReader(string(data)))
decoder.DisallowUnknownFields()

if err := decoder.Decode(result); err != nil {
return driver.WithStack(err)
}

if err := json.Unmarshal(data, result); err != nil {
fmt.Printf("Struct: %s \n", reflect.TypeOf(result).String())
fmt.Printf("Response: %s \n\n", string(data))
return driver.WithStack(errors.New(fmt.Sprintf("Struct: %s, Error: %s", reflect.TypeOf(result).String(), err.Error())))
}
case driver.ContentTypeVelocypack:
if err := velocypack.Unmarshal(velocypack.Slice(data), result); err != nil {
return driver.WithStack(err)
}
default:
return driver.WithStack(fmt.Errorf("unsupported content type %d", int(c.ct)))
}
return nil
}

type responseDebugWrapper struct {
*httpJSONResponse
}

func (r *responseDebugWrapper) ParseBody(field string, result interface{}) error {
if field == "" {
decoder := json.NewDecoder(strings.NewReader(string(r.httpJSONResponse.rawResponse)))
decoder.DisallowUnknownFields()

if err := decoder.Decode(result); err != nil {
fmt.Printf("Struct: %s \n", reflect.TypeOf(result).String())
fmt.Printf("Response: %s \n\n", string(r.httpJSONResponse.rawResponse))
return driver.WithStack(errors.New(fmt.Sprintf("Struct: %s, Error: %s", reflect.TypeOf(result).String(), err.Error())))
}
}
return r.httpJSONResponse.ParseBody(field, result)
}
26 changes: 25 additions & 1 deletion test/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ func createConnectionFromEnvWitLog(t testEnv, logger zerolog.Logger) driver.Conn

// createConnectionFromEnv initializes a Connection from information specified in environment variables.
func createConnectionFromEnv(t testEnv) driver.Connection {
disallowUnknownFields := os.Getenv("TEST_DISALLOW_UNKNOWN_FIELDS")
if disallowUnknownFields == "true" {
return createConnection(t, true)
}
return createConnection(t, false)
}

// createConnection initializes a Connection from information specified in environment variables.
func createConnection(t testEnv, disallowUnknownFields bool) driver.Connection {
connSpec := os.Getenv("TEST_CONNECTION")
connVer := os.Getenv("TEST_CVERSION")
switch connSpec {
Expand All @@ -184,6 +193,9 @@ func createConnectionFromEnv(t testEnv) driver.Connection {
if err != nil {
t.Fatalf("Failed to create new vst connection: %s", describe(err))
}
if disallowUnknownFields {
return http.NewConnectionDebugWrapper(conn, driver.ContentTypeVelocypack)
}
return conn

case "http", "":
Expand All @@ -196,6 +208,9 @@ func createConnectionFromEnv(t testEnv) driver.Connection {
if err != nil {
t.Fatalf("Failed to create new http connection: %s", describe(err))
}
if disallowUnknownFields {
return http.NewConnectionDebugWrapper(conn, config.ContentType)
}
return conn

default:
Expand All @@ -206,6 +221,15 @@ func createConnectionFromEnv(t testEnv) driver.Connection {

// createClientFromEnv initializes a Client from information specified in environment variables.
func createClientFromEnv(t testEnv, waitUntilReady bool) driver.Client {
disallowUnknownFields := os.Getenv("TEST_DISALLOW_UNKNOWN_FIELDS")
if disallowUnknownFields == "true" {
return createClient(t, waitUntilReady, true)
}
return createClient(t, waitUntilReady, false)
}

// createClient initializes a Client from information specified in environment variables.
func createClient(t testEnv, waitUntilReady bool, disallowUnknownFields bool) driver.Client {
runPProfServerOnce.Do(func() {
if os.Getenv("TEST_PPROF") != "" {
go func() {
Expand All @@ -217,7 +241,7 @@ func createClientFromEnv(t testEnv, waitUntilReady bool) driver.Client {
}
})

conn := createConnectionFromEnv(t)
conn := createConnection(t, disallowUnknownFields)
if os.Getenv("TEST_REQUEST_LOG") != "" {
conn = WrapLogger(t, conn)
}
Expand Down
3 changes: 2 additions & 1 deletion test/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ func TestCollectionName(t *testing.T) {

// TestCollectionTruncate creates a collection, adds some documents and truncates it.
func TestCollectionTruncate(t *testing.T) {
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
db := ensureDatabase(nil, c, "collection_test", nil, t)
name := "test_collection_truncate"
col, err := db.CreateCollection(nil, name, nil)
Expand Down
18 changes: 16 additions & 2 deletions test/concurrency_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ func TestConcurrentCreateSmallDocuments(t *testing.T) {
if testing.Short() {
t.Skip("Skip on short tests")
}
c := createClientFromEnv(t, true)

// Disable those tests for active failover
if getTestMode() == testModeResilientSingle {
t.Skip("Disabled in active failover mode")
}

// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)

version, err := c.Version(nil)
if err != nil {
Expand Down Expand Up @@ -124,7 +131,14 @@ func TestConcurrentCreateBigDocuments(t *testing.T) {
if testing.Short() {
t.Skip("Skip on short tests")
}
c := createClientFromEnv(t, true)

// Disable those tests for active failover
if getTestMode() == testModeResilientSingle {
t.Skip("Disabled in active failover mode")
}

// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)

version, err := c.Version(nil)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions test/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ func TestCreateCursorWithMaxRuntime(t *testing.T) {
// TestCreateCursor creates several cursors.
func TestCreateCursor(t *testing.T) {
ctx := context.Background()
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
db := ensureDatabase(ctx, c, "cursor_test", nil, t)

// Create data set
Expand Down Expand Up @@ -327,7 +328,8 @@ func TestCreateCursorReturnNull(t *testing.T) {
func TestCreateStreamCursor(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)

version, err := c.Version(nil)
if err != nil {
Expand Down
12 changes: 8 additions & 4 deletions test/document_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func createDocument(ctx context.Context, col driver.Collection, document interfa

// TestCreateDocument creates a document and then checks that it exists.
func TestCreateDocument(t *testing.T) {
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
db := ensureDatabase(nil, c, "document_test", nil, t)
col := ensureCollection(nil, db, "document_test", nil, t)
doc := UserDoc{
Expand Down Expand Up @@ -70,7 +71,8 @@ func TestCreateDocument(t *testing.T) {

// TestCreateDocumentWithKey creates a document with given key and then checks that it exists.
func TestCreateDocumentWithKey(t *testing.T) {
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
db := ensureDatabase(nil, c, "document_test", nil, t)
col := ensureCollection(nil, db, "document_withKey_test", nil, t)
doc := UserDocWithKey{
Expand Down Expand Up @@ -104,7 +106,8 @@ func TestCreateDocumentWithKey(t *testing.T) {
// TestCreateDocumentReturnNew creates a document and checks the document returned in in ReturnNew.
func TestCreateDocumentReturnNew(t *testing.T) {
ctx := context.Background()
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
db := ensureDatabase(ctx, c, "document_test", nil, t)
col := ensureCollection(ctx, db, "document_test", nil, t)
doc := UserDoc{
Expand Down Expand Up @@ -160,7 +163,8 @@ func TestCreateDocumentNil(t *testing.T) {
// TestCreateDocumentInWaitForSyncCollection creates a document in a collection with waitForSync enabled,
// and then checks that it exists.
func TestCreateDocumentInWaitForSyncCollection(t *testing.T) {
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
db := ensureDatabase(nil, c, "document_test", nil, t)
col := ensureCollection(nil, db, "TestCreateDocumentInWaitForSyncCollection", &driver.CreateCollectionOptions{
WaitForSync: true,
Expand Down
5 changes: 3 additions & 2 deletions test/document_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (

// TestReadDocumentWithIfMatch creates a document and reads it with a non-matching revision.
func TestReadDocumentWithIfMatch(t *testing.T) {
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
db := ensureDatabase(nil, c, "document_read_test", nil, t)
col := ensureCollection(nil, db, "document_read_test", nil, t)
doc := UserDoc{
Expand All @@ -50,7 +51,7 @@ func TestReadDocumentWithIfMatch(t *testing.T) {
if err != nil {
t.Fatalf("Failed to read document: %s", describe(err))
}
if meta2 != meta {
if meta2.Key != meta.Key || meta2.Rev != meta.Rev || meta2.ID != meta.ID {
t.Error("Read wrong meta data.")
}

Expand Down
6 changes: 4 additions & 2 deletions test/document_remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ func TestRemoveDocument(t *testing.T) {
// TestRemoveDocumentReturnOld creates a document, removes it checks the ReturnOld value.
func TestRemoveDocumentReturnOld(t *testing.T) {
ctx := context.Background()
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
db := ensureDatabase(ctx, c, "document_test", nil, t)
col := ensureCollection(ctx, db, "document_test", nil, t)
doc := UserDoc{
Expand Down Expand Up @@ -174,7 +175,8 @@ func TestRemoveDocumentKeyEmpty(t *testing.T) {
// removes it and then checks the removal has succeeded.
func TestRemoveDocumentInWaitForSyncCollection(t *testing.T) {
ctx := context.Background()
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
db := ensureDatabase(ctx, c, "document_test", nil, t)
col := ensureCollection(ctx, db, "TestRemoveDocumentInWaitForSyncCollection", &driver.CreateCollectionOptions{
WaitForSync: true,
Expand Down
12 changes: 8 additions & 4 deletions test/document_replace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import (
// TestReplaceDocument creates a document, replaces it and then checks the replacement has succeeded.
func TestReplaceDocument(t *testing.T) {
ctx := context.Background()
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
db := ensureDatabase(ctx, c, "document_test", nil, t)
col := ensureCollection(ctx, db, "document_test", nil, t)
doc := UserDoc{
Expand Down Expand Up @@ -65,7 +66,8 @@ func TestReplaceDocument(t *testing.T) {
// TestReplaceDocumentReturnOld creates a document, replaces it checks the ReturnOld value.
func TestReplaceDocumentReturnOld(t *testing.T) {
ctx := context.Background()
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
db := ensureDatabase(ctx, c, "document_test", nil, t)
col := ensureCollection(ctx, db, "document_test", nil, t)
doc := UserDoc{
Expand Down Expand Up @@ -94,7 +96,8 @@ func TestReplaceDocumentReturnOld(t *testing.T) {
// TestReplaceDocumentReturnNew creates a document, replaces it checks the ReturnNew value.
func TestReplaceDocumentReturnNew(t *testing.T) {
ctx := context.Background()
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
db := ensureDatabase(ctx, c, "document_test", nil, t)
col := ensureCollection(ctx, db, "document_test", nil, t)
doc := UserDoc{
Expand Down Expand Up @@ -219,7 +222,8 @@ func TestReplaceDocumentUpdateNil(t *testing.T) {
// replaces it and then checks the replacement has succeeded.
func TestReplaceDocumentInWaitForSyncCollection(t *testing.T) {
ctx := context.Background()
c := createClientFromEnv(t, true)
// don't use disallowUnknownFields in this test - we have here custom structs defined
c := createClient(t, true, false)
db := ensureDatabase(ctx, c, "document_test", nil, t)
col := ensureCollection(ctx, db, "TestReplaceDocumentInWaitForSyncCollection", &driver.CreateCollectionOptions{
WaitForSync: true,
Expand Down
Loading