[VOL-2736]host and port should be specified as a single argument not as two separate arguments
Change-Id: I312fe753ac0fe62c942f335371e6449809ecfb85
diff --git a/pkg/db/backend.go b/pkg/db/backend.go
index 20bacad..1e23a0f 100644
--- a/pkg/db/backend.go
+++ b/pkg/db/backend.go
@@ -20,7 +20,6 @@
"context"
"errors"
"fmt"
- "strconv"
"time"
"github.com/opencord/voltha-lib-go/v3/pkg/db/kvstore"
@@ -38,9 +37,8 @@
type Backend struct {
Client kvstore.Client
StoreType string
- Host string
- Port int
Timeout time.Duration
+ Address string
PathPrefix string
alive bool // Is this backend connection alive?
liveness chan bool // channel to post alive state
@@ -49,24 +47,22 @@
}
// NewBackend creates a new instance of a Backend structure
-func NewBackend(storeType string, host string, port int, timeout time.Duration, pathPrefix string) *Backend {
+func NewBackend(storeType string, address string, timeout time.Duration, pathPrefix string) *Backend {
var err error
b := &Backend{
StoreType: storeType,
- Host: host,
- Port: port,
+ Address: address,
Timeout: timeout,
LivenessChannelInterval: DefaultLivenessChannelInterval,
PathPrefix: pathPrefix,
alive: false, // connection considered down at start
}
- address := host + ":" + strconv.Itoa(port)
if b.Client, err = b.newClient(address, timeout); err != nil {
logger.Errorw("failed-to-create-kv-client",
log.Fields{
- "type": storeType, "host": host, "port": port,
+ "type": storeType, "address": address,
"timeout": timeout, "prefix": pathPrefix,
"error": err.Error(),
})
diff --git a/pkg/db/backend_test.go b/pkg/db/backend_test.go
index f96ed19..b8c66bd 100644
--- a/pkg/db/backend_test.go
+++ b/pkg/db/backend_test.go
@@ -18,15 +18,15 @@
import (
"context"
- "os"
- "testing"
- "time"
-
mocks "github.com/opencord/voltha-lib-go/v3/pkg/mocks/etcd"
"github.com/phayes/freeport"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
+ "os"
+ "strconv"
+ "testing"
+ "time"
)
const (
@@ -62,14 +62,14 @@
}
func provisionBackendWithEmbeddedEtcdServer(t *testing.T) *Backend {
- backend := NewBackend("etcd", embedEtcdServerHost, embedEtcdServerPort, defaultTimeout, defaultPathPrefix)
+ backend := NewBackend("etcd", embedEtcdServerHost+":"+strconv.Itoa(embedEtcdServerPort), defaultTimeout, defaultPathPrefix)
assert.NotNil(t, backend)
assert.NotNil(t, backend.Client)
return backend
}
func provisionBackendWithDummyEtcdServer(t *testing.T) *Backend {
- backend := NewBackend("etcd", embedEtcdServerHost, dummyEtcdServerPort, defaultTimeout, defaultPathPrefix)
+ backend := NewBackend("etcd", embedEtcdServerHost+":"+strconv.Itoa(dummyEtcdServerPort), defaultTimeout, defaultPathPrefix)
assert.NotNil(t, backend)
assert.NotNil(t, backend.Client)
return backend
@@ -77,14 +77,14 @@
// Create instance using Etcd Kvstore
func TestNewBackend_EtcdKvStore(t *testing.T) {
- backend := NewBackend("etcd", embedEtcdServerHost, embedEtcdServerPort, defaultTimeout, defaultPathPrefix)
+ address := embedEtcdServerHost + ":" + strconv.Itoa(embedEtcdServerPort)
+ backend := NewBackend("etcd", address, defaultTimeout, defaultPathPrefix)
// Verify all attributes of backend have got set correctly
assert.NotNil(t, backend)
assert.NotNil(t, backend.Client)
assert.Equal(t, backend.StoreType, "etcd")
- assert.Equal(t, backend.Host, embedEtcdServerHost)
- assert.Equal(t, backend.Port, embedEtcdServerPort)
+ assert.Equal(t, backend.Address, address)
assert.Equal(t, backend.Timeout, defaultTimeout)
assert.Equal(t, backend.PathPrefix, defaultPathPrefix)
assert.Equal(t, backend.alive, false) // backend is not alive at start
@@ -94,7 +94,7 @@
// Create instance using Consul Kvstore
func TestNewBackend_ConsulKvStore(t *testing.T) {
- backend := NewBackend("consul", embedEtcdServerHost, embedEtcdServerPort, defaultTimeout, defaultPathPrefix)
+ backend := NewBackend("consul", embedEtcdServerHost+":"+strconv.Itoa(embedEtcdServerPort), defaultTimeout, defaultPathPrefix)
// Verify kvstore type attribute of backend has got set correctly
assert.NotNil(t, backend)
@@ -104,7 +104,7 @@
// Create instance using Invalid Kvstore; instance creation should fail
func TestNewBackend_InvalidKvstore(t *testing.T) {
- backend := NewBackend("unknown", embedEtcdServerHost, embedEtcdServerPort, defaultTimeout, defaultPathPrefix)
+ backend := NewBackend("unknown", embedEtcdServerHost+":"+strconv.Itoa(embedEtcdServerPort), defaultTimeout, defaultPathPrefix)
assert.NotNil(t, backend)
assert.Nil(t, backend.Client)