Test network.Load
This commit is contained in:
parent
7f3cbf628f
commit
cb6c11acef
@ -2,21 +2,17 @@ package network
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"isle/toolkit"
|
||||
)
|
||||
|
||||
func TestCreate(t *testing.T) {
|
||||
toolkit.MarkIntegrationTest(t)
|
||||
|
||||
var (
|
||||
h = newIntegrationHarness(t)
|
||||
network = h.createNetwork(t, "primus", nil)
|
||||
)
|
||||
|
||||
gotCreationParams, err := network.GetNetworkCreationParams(h.ctx)
|
||||
gotCreationParams, err := LoadCreationParams(network.stateDir)
|
||||
if err != nil {
|
||||
t.Fatalf("calling GetNetworkCreationParams: %v", err)
|
||||
t.Fatalf("calling LoadCreationParams: %v", err)
|
||||
} else if network.creationParams != gotCreationParams {
|
||||
t.Fatalf(
|
||||
"expected CreationParams %+v, got %+v",
|
||||
@ -25,3 +21,37 @@ func TestCreate(t *testing.T) {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ type integrationHarness struct {
|
||||
}
|
||||
|
||||
func newIntegrationHarness(t *testing.T) *integrationHarness {
|
||||
t.Parallel()
|
||||
toolkit.MarkIntegrationTest(t)
|
||||
|
||||
rootDir, err := os.MkdirTemp("", "isle-network-it-test.*")
|
||||
@ -119,7 +120,7 @@ func (h *integrationHarness) mkDir(t *testing.T, name string) toolkit.Dir {
|
||||
|
||||
type createNetworkOpts struct {
|
||||
creationParams bootstrap.CreationParams
|
||||
noCleanup bool
|
||||
manualShutdown bool
|
||||
}
|
||||
|
||||
func (o *createNetworkOpts) withDefaults() *createNetworkOpts {
|
||||
@ -136,8 +137,11 @@ func (o *createNetworkOpts) withDefaults() *createNetworkOpts {
|
||||
|
||||
type integrationHarnessNetwork struct {
|
||||
Network
|
||||
|
||||
creationParams bootstrap.CreationParams
|
||||
networkConfig daecommon.NetworkConfig
|
||||
stateDir, runtimeDir toolkit.Dir
|
||||
opts *Opts
|
||||
}
|
||||
|
||||
func (h *integrationHarness) createNetwork(
|
||||
@ -207,6 +211,10 @@ func (h *integrationHarness) createNetwork(
|
||||
}
|
||||
}
|
||||
|
||||
networkOpts := &Opts{
|
||||
ChildrenOpts: childrenOpts,
|
||||
}
|
||||
|
||||
network, err := Create(
|
||||
h.ctx,
|
||||
h.logger.WithNamespace("network"),
|
||||
@ -217,15 +225,13 @@ func (h *integrationHarness) createNetwork(
|
||||
opts.creationParams,
|
||||
ipNet,
|
||||
hostName,
|
||||
&Opts{
|
||||
ChildrenOpts: childrenOpts,
|
||||
},
|
||||
networkOpts,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("creating Network: %v", err)
|
||||
}
|
||||
|
||||
if !opts.noCleanup {
|
||||
if !opts.manualShutdown {
|
||||
t.Cleanup(func() {
|
||||
t.Log("Shutting down Network")
|
||||
if err := network.Shutdown(); err != nil {
|
||||
@ -235,6 +241,11 @@ func (h *integrationHarness) createNetwork(
|
||||
}
|
||||
|
||||
return integrationHarnessNetwork{
|
||||
network, opts.creationParams, stateDir, runtimeDir,
|
||||
network,
|
||||
opts.creationParams,
|
||||
networkConfig,
|
||||
stateDir,
|
||||
runtimeDir,
|
||||
networkOpts,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user