85 lines
1.7 KiB
Go
85 lines
1.7 KiB
Go
package network
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestCreate(t *testing.T) {
|
|
var (
|
|
h = newIntegrationHarness(t)
|
|
network = h.createNetwork(t, "primus", nil)
|
|
)
|
|
|
|
gotCreationParams, err := LoadCreationParams(network.stateDir)
|
|
if err != nil {
|
|
t.Fatalf("calling LoadCreationParams: %v", err)
|
|
} else if network.creationParams != gotCreationParams {
|
|
t.Fatalf(
|
|
"expected CreationParams %+v, got %+v",
|
|
network.creationParams,
|
|
gotCreationParams,
|
|
)
|
|
}
|
|
}
|
|
|
|
func TestLoad(t *testing.T) {
|
|
var (
|
|
h = newIntegrationHarness(t)
|
|
network = h.createNetwork(t, "primus", &createNetworkOpts{
|
|
manualShutdown: true,
|
|
})
|
|
)
|
|
|
|
t.Log("Shutting down network")
|
|
if err := network.Shutdown(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
t.Log("Calling Load")
|
|
loadedNetwork, err := Load(
|
|
h.ctx,
|
|
h.logger.WithNamespace("loadedNetwork"),
|
|
network.networkConfig,
|
|
getEnvBinDirPath(),
|
|
network.stateDir,
|
|
h.mkDir(t, "runtime"),
|
|
network.opts,
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("Load failed: %v", err)
|
|
}
|
|
t.Cleanup(func() {
|
|
t.Log("Shutting down loadedNetwork")
|
|
if err := loadedNetwork.Shutdown(); err != nil {
|
|
t.Logf("Shutting down loadedNetwork failed: %v", err)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestJoin(t *testing.T) {
|
|
var (
|
|
h = newIntegrationHarness(t)
|
|
primus = h.createNetwork(t, "primus", nil)
|
|
secondus = h.joinNetwork(t, primus, "secondus", nil)
|
|
)
|
|
|
|
primusHosts, err := primus.GetHosts(h.ctx)
|
|
if err != nil {
|
|
t.Fatalf("getting hosts from primus: %v", err)
|
|
}
|
|
|
|
secondusHosts, err := secondus.GetHosts(h.ctx)
|
|
if err != nil {
|
|
t.Fatalf("getting hosts from secondus: %v", err)
|
|
}
|
|
|
|
if !reflect.DeepEqual(primusHosts, secondusHosts) {
|
|
t.Fatalf(
|
|
"expected primusHosts %+v to equal secondusHosts %+v",
|
|
primusHosts,
|
|
secondusHosts,
|
|
)
|
|
}
|
|
}
|