agent: testing scada client creation in command
This commit is contained in:
parent
495cc41ba4
commit
8eea77d58f
|
@ -25,6 +25,8 @@ func nextConfig() *Config {
|
||||||
idx := int(atomic.AddUint64(&offset, 1))
|
idx := int(atomic.AddUint64(&offset, 1))
|
||||||
conf := DefaultConfig()
|
conf := DefaultConfig()
|
||||||
|
|
||||||
|
conf.Version = "a.b"
|
||||||
|
conf.VersionPrerelease = "c.d"
|
||||||
conf.AdvertiseAddr = "127.0.0.1"
|
conf.AdvertiseAddr = "127.0.0.1"
|
||||||
conf.Bootstrap = true
|
conf.Bootstrap = true
|
||||||
conf.Datacenter = "dc1"
|
conf.Datacenter = "dc1"
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/testutil"
|
"github.com/hashicorp/consul/testutil"
|
||||||
|
@ -246,3 +247,55 @@ func TestSetupAgent_RPCUnixSocket_FileExists(t *testing.T) {
|
||||||
t.Fatalf("bad permissions: %s", fi.Mode())
|
t.Fatalf("bad permissions: %s", fi.Mode())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetupScadaConn(t *testing.T) {
|
||||||
|
// Create a config and assign an infra name
|
||||||
|
conf1 := nextConfig()
|
||||||
|
conf1.AtlasInfrastructure = "hashicorp/test1"
|
||||||
|
conf1.AtlasToken = "abc"
|
||||||
|
|
||||||
|
dir, agent := makeAgent(t, conf1)
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
defer agent.Shutdown()
|
||||||
|
|
||||||
|
cmd := &Command{
|
||||||
|
ShutdownCh: make(chan struct{}),
|
||||||
|
Ui: new(cli.MockUi),
|
||||||
|
agent: agent,
|
||||||
|
}
|
||||||
|
|
||||||
|
// First start creates the scada conn
|
||||||
|
if err := cmd.setupScadaConn(conf1); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
list := cmd.scadaHttp.listener.(*scadaListener)
|
||||||
|
if list == nil || list.addr.infra != "hashicorp/test1" {
|
||||||
|
t.Fatalf("bad: %#v", list)
|
||||||
|
}
|
||||||
|
http1 := cmd.scadaHttp
|
||||||
|
provider1 := cmd.scadaProvider
|
||||||
|
|
||||||
|
// Performing setup again tears down original and replaces
|
||||||
|
// with a new SCADA client.
|
||||||
|
conf2 := nextConfig()
|
||||||
|
conf2.AtlasInfrastructure = "hashicorp/test2"
|
||||||
|
conf2.AtlasToken = "123"
|
||||||
|
if err := cmd.setupScadaConn(conf2); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
if cmd.scadaHttp == http1 || cmd.scadaProvider == provider1 {
|
||||||
|
t.Fatalf("bad: %#v", cmd)
|
||||||
|
}
|
||||||
|
list = cmd.scadaHttp.listener.(*scadaListener)
|
||||||
|
if list == nil || list.addr.infra != "hashicorp/test2" {
|
||||||
|
t.Fatalf("bad: %#v", list)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Original provider and listener must be closed
|
||||||
|
if !provider1.IsShutdown() {
|
||||||
|
t.Fatalf("should be shutdown")
|
||||||
|
}
|
||||||
|
if _, err := http1.listener.Accept(); !strings.Contains(err.Error(), "closed") {
|
||||||
|
t.Fatalf("should be closed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue