Skip to content

Commit 208208c

Browse files
committed
Various fixes, updating Makefile to support all test variants
1 parent 024c45b commit 208208c

9 files changed

Lines changed: 305 additions & 236 deletions

Makefile

Lines changed: 119 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,44 @@ REPOPATH := $(ORGPATH)/$(REPONAME)
2323

2424
SOURCES := $(shell find . -name '*.go')
2525

26+
# Test variables
27+
28+
DBCONTAINER := $(PROJECT)-test-db
29+
TESTCONTAINER := $(PROJECT)-test
30+
31+
ifeq ("$(TEST_AUTH)", "none")
32+
ARANGOENV := -e ARANGO_NO_AUTH=1
33+
TEST_AUTHENTICATION :=
34+
TAGS :=
35+
TESTS := $(REPOPATH) $(REPOPATH)/test
36+
else ifeq ("$(TEST_AUTH)", "rootpw")
37+
ARANGOENV := -e ARANGO_ROOT_PASSWORD=rootpw
38+
TEST_AUTHENTICATION := basic:root:rootpw
39+
TAGS := -tags auth
40+
TESTS := $(REPOPATH)/test
41+
endif
42+
43+
ifeq ("$(TEST_MODE)", "single")
44+
TEST_NET := container:$(DBCONTAINER)
45+
TEST_ENDPOINTS := http://localhost:8529
46+
else
47+
TEST_NET := host
48+
TEST_ENDPOINTS := http://localhost:7002
49+
ifeq ("$(TEST_AUTH)", "rootpw")
50+
CLUSTERENV := JWTSECRET=testing
51+
TEST_AUTHENTICATION := basic:root:
52+
endif
53+
ifeq ("$(TEST_SSL)", "auto")
54+
CLUSTERENV := SSL=auto $(CLUSTERENV)
55+
TEST_ENDPOINTS = https://localhost:7002
56+
endif
57+
endif
58+
59+
ifeq ("$(TEST_BENCHMARK)", "true")
60+
TAGS := -bench=. -run=notests -cpu=1,2,4
61+
TESTS := $(REPOPATH)/test
62+
endif
63+
2664
.PHONY: all build clean run-tests
2765

2866
all: build
@@ -38,9 +76,6 @@ $(GOBUILDDIR):
3876
@rm -f $(REPODIR) && ln -s ../../../.. $(REPODIR)
3977
GOPATH=$(GOBUILDDIR) go get github.com/arangodb/go-velocypack
4078

41-
DBCONTAINER := $(PROJECT)-test-db
42-
TESTCONTAINER := $(PROJECT)-test
43-
4479
run-tests: run-tests-http run-tests-single run-tests-cluster
4580

4681
# Tests of HTTP package
@@ -54,93 +89,95 @@ run-tests-http: $(GOBUILDDIR)
5489
go test $(TESTOPTIONS) $(REPOPATH)/http
5590

5691
# Single server tests
57-
run-tests-single: run-tests-single-with-auth run-tests-single-no-auth
92+
run-tests-single: run-tests-single-json run-tests-single-vpack
5893

59-
run-tests-single-no-auth: $(GOBUILDDIR)
60-
@echo "Single server, no authentication"
61-
@-docker rm -f -v $(DBCONTAINER) $(TESTCONTAINER) &> /dev/null
62-
@docker run -d --name $(DBCONTAINER) \
63-
-e ARANGO_NO_AUTH=1 \
64-
$(ARANGODB)
65-
@docker run \
66-
--name=$(TESTCONTAINER) \
67-
--net=container:$(DBCONTAINER) \
68-
-v $(ROOTDIR):/usr/code \
69-
-e GOPATH=/usr/code/.gobuild \
70-
-e TEST_ENDPOINTS=http://localhost:8529 \
71-
-w /usr/code/ \
72-
golang:$(GOVERSION) \
73-
go test $(TESTOPTIONS) $(REPOPATH) $(REPOPATH)/test
74-
@docker rm -f -v $(TESTCONTAINER) &> /dev/null
75-
@docker rm -f -v $(DBCONTAINER) &> /dev/null
76-
@sleep 3
94+
run-tests-single-json: run-tests-single-json-with-auth run-tests-single-json-no-auth
7795

78-
run-tests-single-with-auth: $(GOBUILDDIR)
79-
@echo "Single server, with authentication"
80-
@-docker rm -f -v $(DBCONTAINER) $(TESTCONTAINER) &> /dev/null
81-
@docker run -d --name $(DBCONTAINER) \
82-
-e ARANGO_ROOT_PASSWORD=rootpw \
83-
$(ARANGODB)
84-
@docker run \
85-
--name=$(TESTCONTAINER) \
86-
--net=container:$(DBCONTAINER) \
87-
-v $(ROOTDIR):/usr/code \
88-
-e GOPATH=/usr/code/.gobuild \
89-
-e TEST_ENDPOINTS=http://localhost:8529 \
90-
-e TEST_AUTHENTICATION=basic:root:rootpw \
91-
-w /usr/code/ \
92-
golang:$(GOVERSION) \
93-
go test -tags auth $(TESTOPTIONS) $(REPOPATH)/test
94-
@docker rm -f -v $(TESTCONTAINER) &> /dev/null
95-
@docker rm -f -v $(DBCONTAINER) &> /dev/null
96-
@sleep 3
96+
run-tests-single-vpack: run-tests-single-vpack-with-auth run-tests-single-vpack-no-auth
97+
98+
run-tests-single-json-no-auth:
99+
@echo "Single server, HTTP+JSON, no authentication"
100+
@${MAKE} TEST_MODE="single" TEST_AUTH="none" TEST_CONTENT_TYPE="json" __run_tests
101+
102+
run-tests-single-vpack-no-auth:
103+
@echo "Single server, HTTP+Velocypack, no authentication"
104+
@${MAKE} TEST_MODE="single" TEST_AUTH="none" TEST_CONTENT_TYPE="vpack" __run_tests
105+
106+
run-tests-single-json-with-auth:
107+
@echo "Single server, HTTP+JSON, with authentication"
108+
@${MAKE} TEST_MODE="single" TEST_AUTH="rootpw" TEST_CONTENT_TYPE="json" __run_tests
109+
110+
run-tests-single-vpack-with-auth:
111+
@echo "Single server, HTTP+Velocypack, with authentication"
112+
@${MAKE} TEST_MODE="single" TEST_AUTH="rootpw" TEST_CONTENT_TYPE="vpack" __run_tests
97113

98114
# Cluster mode tests
99-
run-tests-cluster: run-tests-cluster-no-auth run-tests-cluster-with-auth run-tests-cluster-ssl
115+
run-tests-cluster: run-tests-cluster-json run-tests-cluster-vpack
100116

101-
run-tests-cluster-no-auth: $(GOBUILDDIR)
102-
@echo "Cluster server, no authentication"
103-
@PROJECT=$(PROJECT) ARANGODB=$(ARANGODB) $(ROOTDIR)/test/cluster.sh start
104-
docker run \
105-
--rm \
106-
--net=host \
107-
-v $(ROOTDIR):/usr/code \
108-
-e GOPATH=/usr/code/.gobuild \
109-
-e TEST_ENDPOINTS=http://localhost:7002 \
110-
-w /usr/code/ \
111-
golang:$(GOVERSION) \
112-
go test $(TESTOPTIONS) $(REPOPATH)/test
113-
@PROJECT=$(PROJECT) ARANGODB=$(ARANGODB) $(ROOTDIR)/test/cluster.sh cleanup
117+
run-tests-cluster-json: run-tests-cluster-json-no-auth run-tests-cluster-json-with-auth run-tests-cluster-json-ssl
118+
119+
run-tests-cluster-vpack: run-tests-cluster-vpack-no-auth run-tests-cluster-vpack-with-auth run-tests-cluster-vpack-ssl
120+
121+
run-tests-cluster-json-no-auth: $(GOBUILDDIR)
122+
@echo "Cluster server, JSON, no authentication"
123+
@${MAKE} TEST_MODE="cluster" TEST_AUTH="none" TEST_CONTENT_TYPE="json" __run_tests
114124

115-
run-tests-cluster-with-auth: $(GOBUILDDIR)
125+
run-tests-cluster-vpack-no-auth: $(GOBUILDDIR)
126+
@echo "Cluster server, Velocpack, no authentication"
127+
@${MAKE} TEST_MODE="cluster" TEST_AUTH="none" TEST_CONTENT_TYPE="vpack" __run_tests
128+
129+
run-tests-cluster-json-with-auth: $(GOBUILDDIR)
116130
@echo "Cluster server, with authentication"
117-
@PROJECT=$(PROJECT) ARANGODB=$(ARANGODB) TMPDIR=${GOBUILDDIR} JWTSECRET=testing $(ROOTDIR)/test/cluster.sh start
118-
docker run \
119-
--rm \
120-
--net=host \
121-
-v $(ROOTDIR):/usr/code \
122-
-e GOPATH=/usr/code/.gobuild \
123-
-e TEST_ENDPOINTS=http://localhost:7002 \
124-
-e TEST_AUTHENTICATION=basic:root: \
125-
-w /usr/code/ \
126-
golang:$(GOVERSION) \
127-
go test -tags auth $(TESTOPTIONS) $(REPOPATH)/test
128-
@PROJECT=$(PROJECT) ARANGODB=$(ARANGODB) $(ROOTDIR)/test/cluster.sh cleanup
131+
@${MAKE} TEST_MODE="cluster" TEST_AUTH="rootpw" TEST_CONTENT_TYPE="json" __run_tests
132+
133+
run-tests-cluster-vpack-with-auth: $(GOBUILDDIR)
134+
@echo "Cluster server, Velocypack, with authentication"
135+
@${MAKE} TEST_MODE="cluster" TEST_AUTH="rootpw" TEST_CONTENT_TYPE="vpack" __run_tests
129136

130-
run-tests-cluster-ssl: $(GOBUILDDIR)
137+
run-tests-cluster-json-ssl: $(GOBUILDDIR)
131138
@echo "Cluster server, SSL, with authentication"
132-
@PROJECT=$(PROJECT) ARANGODB=$(ARANGODB) SSL=auto TMPDIR=${GOBUILDDIR} JWTSECRET=testing $(ROOTDIR)/test/cluster.sh start
139+
@${MAKE} TEST_MODE="cluster" TEST_AUTH="rootpw" TEST_SSL="auto" TEST_CONTENT_TYPE="json" __run_tests
140+
141+
run-tests-cluster-vpack-ssl: $(GOBUILDDIR)
142+
@echo "Cluster server, Velocypack, SSL, with authentication"
143+
@${MAKE} TEST_MODE="cluster" TEST_AUTH="rootpw" TEST_SSL="auto" TEST_CONTENT_TYPE="vpack" __run_tests
144+
145+
# Internal test tasks
146+
__run_tests: $(GOBUILDDIR) __test_prepare __test_go_test __test_cleanup
147+
148+
__test_go_test:
133149
docker run \
134-
--rm \
135-
--net=host \
150+
--name=$(TESTCONTAINER) \
151+
--net=$(TEST_NET) \
136152
-v $(ROOTDIR):/usr/code \
137153
-e GOPATH=/usr/code/.gobuild \
138-
-e TEST_ENDPOINTS=https://localhost:7002 \
139-
-e TEST_AUTHENTICATION=basic:root: \
154+
-e TEST_ENDPOINTS=$(TEST_ENDPOINTS) \
155+
-e TEST_AUTHENTICATION=$(TEST_AUTHENTICATION) \
156+
-e TEST_CONTENT_TYPE=$(TEST_CONTENT_TYPE) \
140157
-w /usr/code/ \
141158
golang:$(GOVERSION) \
142-
go test -tags auth $(TESTOPTIONS) $(REPOPATH)/test
159+
go test $(TAGS) $(TESTOPTIONS) $(TESTS)
160+
161+
__test_prepare:
162+
ifeq ("$(TEST_MODE)", "single")
163+
@-docker rm -f -v $(DBCONTAINER) $(TESTCONTAINER) &> /dev/null
164+
docker run -d --name $(DBCONTAINER) \
165+
$(ARANGOENV) \
166+
$(ARANGODB)
167+
else
168+
@-docker rm -f -v $(TESTCONTAINER) &> /dev/null
169+
@PROJECT=$(PROJECT) ARANGODB=$(ARANGODB) TMPDIR=${GOBUILDDIR} $(CLUSTERENV) $(ROOTDIR)/test/cluster.sh start
170+
endif
171+
172+
__test_cleanup:
173+
@docker rm -f -v $(TESTCONTAINER) &> /dev/null
174+
ifeq ("$(TEST_MODE)", "single")
175+
@docker rm -f -v $(DBCONTAINER) &> /dev/null
176+
else
143177
@PROJECT=$(PROJECT) ARANGODB=$(ARANGODB) $(ROOTDIR)/test/cluster.sh cleanup
178+
endif
179+
@sleep 3
180+
144181

145182
run-tests-cluster-failover: $(GOBUILDDIR)
146183
# Note that we use 127.0.0.1:7002.. as endpoints, so we force using IPv4
@@ -165,21 +202,10 @@ run-tests-cluster-cleanup:
165202
@PROJECT=$(PROJECT) ARANGODB=$(ARANGODB) $(ROOTDIR)/test/cluster.sh cleanup
166203

167204
# Benchmarks
168-
run-benchmarks-single-no-auth: $(GOBUILDDIR)
169-
@echo "Single server, no authentication"
170-
@-docker rm -f -v $(DBCONTAINER) $(TESTCONTAINER) &> /dev/null
171-
@docker run -d --name $(DBCONTAINER) \
172-
-e ARANGO_NO_AUTH=1 \
173-
$(ARANGODB)
174-
@docker run \
175-
--name=$(TESTCONTAINER) \
176-
--net=container:$(DBCONTAINER) \
177-
-v $(ROOTDIR):/usr/code \
178-
-e GOPATH=/usr/code/.gobuild \
179-
-e TEST_ENDPOINTS=http://localhost:8529 \
180-
-w /usr/code/ \
181-
golang:$(GOVERSION) \
182-
go test $(TESTOPTIONS) -bench=. -run=notests -cpu=1,2,4 $(REPOPATH)/test
183-
@docker rm -f -v $(TESTCONTAINER) &> /dev/null
184-
@docker rm -f -v $(DBCONTAINER) &> /dev/null
185-
@sleep 3
205+
run-benchmarks-single-json-no-auth:
206+
@echo "Benchmarks: Single server, JSON no authentication"
207+
@${MAKE} TEST_MODE="single" TEST_AUTH="none" TEST_CONTENT_TYPE="json" TEST_BENCHMARK="true" __run_tests
208+
209+
run-benchmarks-single-vpack-no-auth:
210+
@echo "Benchmarks: Single server, Velocypack, no authentication"
211+
@${MAKE} TEST_MODE="single" TEST_AUTH="none" TEST_CONTENT_TYPE="vpack" TEST_BENCHMARK="true" __run_tests
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// Author Ewout Prangsma
2121
//
2222

23-
package http
23+
package driver
2424

2525
import "fmt"
2626

http/connection.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type ConnectionConfig struct {
5959
// Cluster configuration settings
6060
cluster.ConnectionConfig
6161
// ContentType specified type of content encoding to use.
62-
ContentType ContentType
62+
ContentType driver.ContentType
6363
}
6464

6565
// NewConnection creates a new HTTP connection based on the given configuration settings.
@@ -107,7 +107,7 @@ func newHTTPConnection(endpoint string, config ConnectionConfig) (driver.Connect
107107
// httpConnection implements an HTTP + JSON connection to an arangodb server.
108108
type httpConnection struct {
109109
endpoint url.URL
110-
contentType ContentType
110+
contentType driver.ContentType
111111
client *http.Client
112112
}
113113

@@ -125,17 +125,17 @@ func (c *httpConnection) NewRequest(method, path string) (driver.Request, error)
125125
return nil, driver.WithStack(driver.InvalidArgumentError{Message: fmt.Sprintf("Invalid method '%s'", method)})
126126
}
127127
ct := c.contentType
128-
if strings.Contains(path, "gharial") || strings.Contains(path, "import") {
129-
ct = ContentTypeJSON
128+
if strings.Contains(path, "gharial") /*|| strings.Contains(path, "import")*/ {
129+
ct = driver.ContentTypeJSON
130130
}
131131
switch ct {
132-
case ContentTypeJSON:
132+
case driver.ContentTypeJSON:
133133
r := &httpJSONRequest{
134134
method: method,
135135
path: path,
136136
}
137137
return r, nil
138-
case ContentTypeVelocypack:
138+
case driver.ContentTypeVelocypack:
139139
r := &httpVPackRequest{
140140
method: method,
141141
path: path,
@@ -202,15 +202,19 @@ func (c *httpConnection) Do(ctx context.Context, req driver.Request) (driver.Res
202202
// Unmarshal unmarshals the given raw object into the given result interface.
203203
func (c *httpConnection) Unmarshal(data driver.RawObject, result interface{}) error {
204204
ct := c.contentType
205-
if len(data) >= 2 && data[0] == '{' && data[len(data)-1] == '}' {
206-
ct = ContentTypeJSON
205+
if ct == driver.ContentTypeVelocypack && len(data) >= 2 {
206+
// Poor mans auto detection of json
207+
l := len(data)
208+
if (data[0] == '{' && data[l-1] == '}') || (data[0] == '[' && data[l-1] == ']') {
209+
ct = driver.ContentTypeJSON
210+
}
207211
}
208212
switch ct {
209-
case ContentTypeJSON:
213+
case driver.ContentTypeJSON:
210214
if err := json.Unmarshal(data, result); err != nil {
211215
return driver.WithStack(err)
212216
}
213-
case ContentTypeVelocypack:
217+
case driver.ContentTypeVelocypack:
214218
//panic(velocypack.Slice(data))
215219
if err := velocypack.Unmarshal(velocypack.Slice(data), result); err != nil {
216220
return driver.WithStack(err)

http/request_vpack.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,13 @@ func (r *httpVPackRequest) SetBodyImportArray(bodyArray interface{}) (driver.Req
133133
return nil, driver.WithStack(driver.InvalidArgumentError{Message: fmt.Sprintf("bodyArray must be slice, got %s", bodyArrayVal.Kind())})
134134
}
135135
// Render elements
136-
elementCount := bodyArrayVal.Len()
137136
buf := &bytes.Buffer{}
138137
encoder := velocypack.NewEncoder(buf)
139-
for i := 0; i < elementCount; i++ {
140-
entryVal := bodyArrayVal.Index(i)
141-
if isNil(entryVal) {
142-
buf.Write(velocypack.NullSlice())
143-
//buf.WriteString("\n")
144-
} else {
145-
if err := encoder.Encode(entryVal.Interface()); err != nil {
146-
return nil, driver.WithStack(err)
147-
}
148-
}
138+
if err := encoder.Encode(bodyArray); err != nil {
139+
return nil, driver.WithStack(err)
149140
}
150141
r.body = buf.Bytes()
142+
r.SetQuery("type", "list")
151143
return r, nil
152144
}
153145

test/client_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ func getEndpointsFromEnv(t testEnv) []string {
6262
return eps
6363
}
6464

65+
// getContentTypeFromEnv returns the content-type specified in the TEST_CONTENT_TYPE
66+
// environment variable (json|vpack).
67+
func getContentTypeFromEnv(t testEnv) driver.ContentType {
68+
switch ct := os.Getenv("TEST_CONTENT_TYPE"); ct {
69+
case "vpack":
70+
return driver.ContentTypeVelocypack
71+
case "json", "":
72+
return driver.ContentTypeJSON
73+
default:
74+
t.Fatalf("Unknown content type '%s'", ct)
75+
return 0
76+
}
77+
}
78+
6579
// createAuthenticationFromEnv initializes an authentication specified in the TEST_AUTHENTICATION
6680
// environment variable.
6781
func createAuthenticationFromEnv(t testEnv) driver.Authentication {
@@ -92,7 +106,7 @@ func createConnectionFromEnv(t testEnv) driver.Connection {
92106
config := http.ConnectionConfig{
93107
Endpoints: getEndpointsFromEnv(t),
94108
TLSConfig: &tls.Config{InsecureSkipVerify: true},
95-
ContentType: http.ContentTypeVelocypack,
109+
ContentType: getContentTypeFromEnv(t),
96110
}
97111
conn, err := http.NewConnection(config)
98112
if err != nil {
@@ -146,7 +160,7 @@ func waitUntilServerAvailable(ctx context.Context, c driver.Client, t testEnv) b
146160
return
147161
} else {
148162
cancel()
149-
t.Logf("Version failed: %s %#v", describe(err), err)
163+
//t.Logf("Version failed: %s %#v", describe(err), err)
150164
time.Sleep(time.Second)
151165
}
152166
}

0 commit comments

Comments
 (0)