Skip to content

Commit 2e1d598

Browse files
Add tests for ArangoDB connection setup
1 parent 522e888 commit 2e1d598

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

dbee/adapters/arango_test.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package adapters
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestArango_Connect(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
connectionURL string
13+
wantErr bool
14+
messageErr string
15+
database string
16+
}{
17+
{
18+
name: "should fail with invalid url format",
19+
connectionURL: "://invalid",
20+
wantErr: true,
21+
messageErr: "failed to parse connection string",
22+
},
23+
{
24+
name: "should fail with missing password",
25+
connectionURL: "http://token@hostname:8529",
26+
wantErr: true,
27+
messageErr: "arango: missing password",
28+
},
29+
{
30+
name: "should fail with missing password with root user",
31+
connectionURL: "http://root@hostname.com:8529",
32+
database: "_system",
33+
},
34+
35+
{
36+
name: "should succeed with valid connection with root user",
37+
connectionURL: "http://root@hostname.com:8529?allow_empty_root_password=true",
38+
database: "_system",
39+
},
40+
{
41+
name: "should succeed with valid connection",
42+
connectionURL: "http://token:dummytoken@hostname.com:8529",
43+
database: "_system",
44+
},
45+
{
46+
name: "should succeed to parse database name from path",
47+
connectionURL: "http://token:dummytoken@hostname.com:8529/_db/testdb",
48+
database: "testdb",
49+
},
50+
}
51+
for _, tt := range tests {
52+
t.Run(tt.name, func(t *testing.T) {
53+
t.Parallel()
54+
55+
d := &Arango{}
56+
got, err := d.Connect(tt.connectionURL)
57+
58+
if tt.wantErr {
59+
assert.NotEqual(t, "", tt.messageErr)
60+
assert.Error(t, err)
61+
assert.Contains(t, err.Error(), tt.messageErr)
62+
return
63+
}
64+
assert.NoError(t, err)
65+
assert.NotNil(t, got)
66+
assert.Equal(t, tt.database, got.(*arangoDriver).dbName)
67+
})
68+
}
69+
}

0 commit comments

Comments
 (0)