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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ services:
language: go

env:
- TEST_SUITE=run-tests-http
- TEST_SUITE=run-unit-tests
- TEST_SUITE=run-tests-single ARANGODB=arangodb:3.5
- TEST_SUITE=run-tests-single ARANGODB=arangodb/arangodb:latest
- TEST_SUITE=run-tests-single ARANGODB=arangodb/arangodb-preview:latest
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,19 @@ changelog:
--no-author \
--unreleased-label "Master"

run-tests: run-tests-http run-tests-single run-tests-resilientsingle run-tests-cluster
run-tests: run-unit-tests run-tests-single run-tests-resilientsingle run-tests-cluster

# Tests of HTTP package
run-tests-http:
# The below rule exists only for backward compatibility.
run-tests-http: run-unit-tests

run-unit-tests:
@docker run \
--rm \
-v "${ROOTDIR}":/usr/code \
-e CGO_ENABLED=0 \
-w /usr/code/ \
golang:$(GOVERSION) \
go test $(TESTOPTIONS) $(REPOPATH)/http
go test $(TESTOPTIONS) $(REPOPATH)/http $(REPOPATH)/agency

# Single server tests
run-tests-single: run-tests-single-json run-tests-single-vpack run-tests-single-vst-1.0 $(VST11_SINGLE_TESTS)
Expand Down
15 changes: 14 additions & 1 deletion agency/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ package agency

import "time"

type Key []string

// KeyChanger describes how operation should be performed on a key in the agency
type KeyChanger interface {
// GetKey returns which key must be changed
Expand All @@ -41,7 +43,18 @@ type KeyChanger interface {
}

type keyCommon struct {
key []string
key Key
}

// CreateSubKey creates new key based on receiver key.
// Returns new key with new allocated memory.
func (k Key) CreateSubKey(elements ...string) Key {
NewKey := make([]string, 0, len(k)+len(elements))

NewKey = append(NewKey, k...)
NewKey = append(NewKey, elements...)

return NewKey
}

func (k *keyCommon) GetKey() string {
Expand Down
51 changes: 51 additions & 0 deletions agency/operation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package agency_test

import (
"github.com/arangodb/go-driver/agency"
"github.com/stretchr/testify/require"
"testing"
)

func TestCreateSubKey(t *testing.T) {
testCases := []struct {
name string
elements []string
key agency.Key
}{
{
name: "Create a new key based on not empty key with not empty elements",
key: agency.Key{"level1", "level2"},
elements: []string{"level3"},
},
{
name: "Create a new key based on not empty key with empty elements",
key: agency.Key{"level1", "level2"},
},
{
name: "Create a new key based on empty key",
elements: []string{"level3"},
},
{
name: "Create a new key based on empty key with empty elements",
},
}

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
newKey := testCase.key.CreateSubKey(testCase.elements...)

require.Len(t, newKey, len(testCase.key)+len(testCase.elements))
if len(testCase.key) > 0 && &testCase.key[0] == &newKey[0] {
require.Fail(t, "New key should have always different address")
}

for i, s := range testCase.key {
require.Equal(t, s, newKey[i])
}
for i, s := range testCase.elements {
require.Equal(t, s, newKey[i+len(testCase.key)])
}
})
}

}