1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
package scada
import (
"net"
"reflect"
"testing"
"github.com/hashicorp/scada-client"
)
func TestProviderService(t *testing.T) {
conf := &Config{
Version: "0.5.0rc1",
Service: "nomad",
ResourceType: "nomad-cluster",
Meta: map[string]string{
"auto-join": "true",
"region": "global",
"datacenter": "dc1",
"client": "false",
"server": "true",
},
}
ps := providerService(conf)
expect := &client.ProviderService{
Service: "nomad",
ServiceVersion: "0.5.0rc1",
Capabilities: map[string]int{},
Meta: map[string]string{
"auto-join": "true",
"region": "global",
"datacenter": "dc1",
"client": "false",
"server": "true",
},
ResourceType: "nomad-cluster",
}
if !reflect.DeepEqual(ps, expect) {
t.Fatalf("bad: %v", ps)
}
}
func TestProviderConfig(t *testing.T) {
conf := &Config{
Version: "0.5.0rc1",
Service: "nomad",
ResourceType: "nomad-cluster",
Meta: map[string]string{
"auto-join": "true",
"region": "global",
"datacenter": "dc1",
"client": "false",
"server": "true",
},
}
conf.Atlas = AtlasConfig{
Infrastructure: "armon/test",
Token: "foobarbaz",
Endpoint: "foo.bar:1111",
}
pc := providerConfig(conf)
expect := &client.ProviderConfig{
Service: &client.ProviderService{
Service: "nomad",
ServiceVersion: "0.5.0rc1",
Capabilities: map[string]int{},
Meta: map[string]string{
"auto-join": "true",
"region": "global",
"datacenter": "dc1",
"client": "false",
"server": "true",
},
ResourceType: "nomad-cluster",
},
Handlers: map[string]client.CapabilityProvider{},
Endpoint: "foo.bar:1111",
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")
}
}
|