mirror of https://github.com/status-im/consul.git
agent: Adding SCADA tests
This commit is contained in:
parent
c495a5434d
commit
8fb642d332
|
@ -96,9 +96,9 @@ type scadaListener struct {
|
|||
}
|
||||
|
||||
// newScadaListener returns a new listener
|
||||
func newScadaListener(cluster string) *scadaListener {
|
||||
func newScadaListener(infra string) *scadaListener {
|
||||
l := &scadaListener{
|
||||
addr: &scadaAddr{cluster},
|
||||
addr: &scadaAddr{infra},
|
||||
pending: make(chan net.Conn),
|
||||
closedCh: make(chan struct{}),
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ func (s *scadaListener) Addr() net.Addr {
|
|||
|
||||
// scadaAddr is used to return a net.Addr for SCADA
|
||||
type scadaAddr struct {
|
||||
cluster string
|
||||
infra string
|
||||
}
|
||||
|
||||
func (s *scadaAddr) Network() string {
|
||||
|
@ -163,7 +163,7 @@ func (s *scadaAddr) Network() string {
|
|||
}
|
||||
|
||||
func (s *scadaAddr) String() string {
|
||||
return fmt.Sprintf("SCADA::Atlas::%s", s.cluster)
|
||||
return fmt.Sprintf("SCADA::Atlas::%s", s.infra)
|
||||
}
|
||||
|
||||
type scadaRWC struct {
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
package agent
|
||||
|
||||
import (
|
||||
"net"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/scada-client"
|
||||
)
|
||||
|
||||
func TestProviderService(t *testing.T) {
|
||||
conf := DefaultConfig()
|
||||
conf.Version = "0.5.0"
|
||||
conf.VersionPrerelease = "rc1"
|
||||
conf.AtlasJoin = true
|
||||
conf.Server = true
|
||||
ps := ProviderService(conf)
|
||||
|
||||
expect := &client.ProviderService{
|
||||
Service: "consul",
|
||||
ServiceVersion: "0.5.0rc1",
|
||||
Capabilities: map[string]int{
|
||||
"http": 1,
|
||||
},
|
||||
Meta: map[string]string{
|
||||
"auto-join": "true",
|
||||
"datacenter": "dc1",
|
||||
"server": "true",
|
||||
},
|
||||
ResourceType: "infrastructures",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(ps, expect) {
|
||||
t.Fatalf("bad: %v", ps)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderConfig(t *testing.T) {
|
||||
conf := DefaultConfig()
|
||||
conf.Version = "0.5.0"
|
||||
conf.VersionPrerelease = "rc1"
|
||||
conf.AtlasJoin = true
|
||||
conf.Server = true
|
||||
conf.AtlasInfrastructure = "armon/test"
|
||||
conf.AtlasToken = "foobarbaz"
|
||||
pc := ProviderConfig(conf)
|
||||
|
||||
expect := &client.ProviderConfig{
|
||||
Service: &client.ProviderService{
|
||||
Service: "consul",
|
||||
ServiceVersion: "0.5.0rc1",
|
||||
Capabilities: map[string]int{
|
||||
"http": 1,
|
||||
},
|
||||
Meta: map[string]string{
|
||||
"auto-join": "true",
|
||||
"datacenter": "dc1",
|
||||
"server": "true",
|
||||
},
|
||||
ResourceType: "infrastructures",
|
||||
},
|
||||
Handlers: map[string]client.CapabilityProvider{
|
||||
"http": nil,
|
||||
},
|
||||
ResourceGroup: "armon/test",
|
||||
Token: "foobarbaz",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(pc, expect) {
|
||||
t.Fatalf("bad: %v", pc)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSCADAListener(t *testing.T) {
|
||||
list := newScadaListener("armon/test")
|
||||
defer list.Close()
|
||||
|
||||
var raw interface{} = list
|
||||
_, ok := raw.(net.Listener)
|
||||
if !ok {
|
||||
t.Fatalf("bad")
|
||||
}
|
||||
|
||||
a, b := net.Pipe()
|
||||
defer a.Close()
|
||||
defer b.Close()
|
||||
|
||||
go list.Push(a)
|
||||
out, err := list.Accept()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if out != a {
|
||||
t.Fatalf("bad")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSCADAAddr(t *testing.T) {
|
||||
var addr interface{} = &scadaAddr{"armon/test"}
|
||||
_, ok := addr.(net.Addr)
|
||||
if !ok {
|
||||
t.Fatalf("bad")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue