mirror of https://github.com/docker/docs.git
add a few tests
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
88bff68a5a
commit
d6baf8bbe2
|
@ -34,8 +34,9 @@ type DiscoveryService interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
discoveries map[string]func() DiscoveryService
|
discoveries map[string]func() DiscoveryService
|
||||||
ErrNotSupported = errors.New("discovery service not supported")
|
ErrNotSupported = errors.New("discovery service not supported")
|
||||||
|
ErrNotImplemented = errors.New("not implemented in this discovery service")
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package etcd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestInitialize(t *testing.T) {
|
||||||
|
discovery := &EtcdDiscoveryService{}
|
||||||
|
assert.Error(t, discovery.Initialize("127.0.0.1/path", 0))
|
||||||
|
assert.Equal(t, discovery.path, "/path/")
|
||||||
|
|
||||||
|
assert.Error(t, discovery.Initialize("127.0.0.1,127.0.0.2,127.0.0.3/path", 0))
|
||||||
|
assert.Equal(t, discovery.path, "/path/")
|
||||||
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
package file
|
package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -54,5 +53,5 @@ func (s *FileDiscoveryService) Watch(callback discovery.WatchCallback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *FileDiscoveryService) Register(addr string) error {
|
func (s *FileDiscoveryService) Register(addr string) error {
|
||||||
return errors.New("unimplemented")
|
return discovery.ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package file
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestInitialize(t *testing.T) {
|
||||||
|
discovery := &FileDiscoveryService{}
|
||||||
|
discovery.Initialize("/path/to/file", 0)
|
||||||
|
assert.Equal(t, discovery.path, "/path/to/file")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRegister(t *testing.T) {
|
||||||
|
discovery := &FileDiscoveryService{path: "/path/to/file"}
|
||||||
|
assert.Error(t, discovery.Register("0.0.0.0"))
|
||||||
|
}
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInit(t *testing.T) {
|
func TestInitialize(t *testing.T) {
|
||||||
discovery := &TokenDiscoveryService{}
|
discovery := &TokenDiscoveryService{}
|
||||||
discovery.Initialize("token", 0)
|
discovery.Initialize("token", 0)
|
||||||
assert.Equal(t, discovery.token, "token")
|
assert.Equal(t, discovery.token, "token")
|
||||||
|
@ -18,7 +18,7 @@ func TestInit(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRegister(t *testing.T) {
|
func TestRegister(t *testing.T) {
|
||||||
discovery := TokenDiscoveryService{token: "TEST_TOKEN", url: DISCOVERY_URL}
|
discovery := &TokenDiscoveryService{token: "TEST_TOKEN", url: DISCOVERY_URL}
|
||||||
expected := "127.0.0.1:2675"
|
expected := "127.0.0.1:2675"
|
||||||
assert.NoError(t, discovery.Register(expected))
|
assert.NoError(t, discovery.Register(expected))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue