Beispiel #1
0
func TestServiceLinkBadChainWithoutChainInDefinition(t *testing.T) {
	defer tests.RemoveAllContainers()

	if err := tests.FakeServiceDefinition(erisDir, "fake", `
[service]
name = "fake"
image = "`+path.Join(ver.ERIS_REG_DEF, ver.ERIS_IMG_IPFS)+`"
`); err != nil {
		t.Fatalf("can't create a fake service definition: %v", err)
	}

	do := def.NowDo()
	do.Operations.Args = []string{"fake"}
	do.Operations.ContainerNumber = 1
	do.ChainName = "non-existent-chain"

	// [pv]: is this a bug? the service which doesn't have a
	// "chain" in its definition file doesn't care about linking at all.
	if err := services.StartService(do); err != nil {
		t.Fatalf("expect service to start, got %v", err)
	}

	if n := util.HowManyContainersRunning("fake", def.TypeService); n != 1 {
		t.Fatalf("expecting 1 service containers, got %v", n)
	}
	if n := util.HowManyContainersExisting("fake", def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data containers, got %v", n)
	}
}
Beispiel #2
0
func TestChainsNewConfigOpts(t *testing.T) {
	defer tests.RemoveAllContainers()
	const (
		chain = "test-config-opts"
	)

	do := def.NowDo()
	do.Name = chain
	do.ConfigOpts = []string{"moniker=satoshi", "p2p=1.1.1.1:42", "fast-sync=true"}
	do.Operations.ContainerNumber = 1
	do.Operations.PublishAllPorts = true
	if err := NewChain(do); err != nil {
		t.Fatalf("expected to create a new chain, got %v", err)
	}

	do = def.NowDo()
	do.Name = chain
	do.Operations.Args = []string{"cat", fmt.Sprintf("/home/eris/.eris/chains/%s/config.toml", chain)}
	if err := ExecChain(do); err != nil {
		t.Fatalf("expected chain to execute, got %v", err)
	}

	args := []string{"cat", fmt.Sprintf("/home/eris/.eris/chains/%s/config.toml", chain)}
	if out := exec(t, chain, args); !strings.Contains(out, "satoshi") || !strings.Contains(out, "1.1.1.1:42") {
		t.Fatalf("expected to find set options in config file, got %v", out)
	}
}
Beispiel #3
0
func TestRmService(t *testing.T) {
	defer tests.RemoveAllContainers()

	start(t, servName, false)
	if n := util.HowManyContainersRunning(servName, def.TypeService); n != 1 {
		t.Fatalf("expecting 1 running service container, got %v", n)
	}
	if n := util.HowManyContainersExisting(servName, def.TypeData); n != 1 {
		t.Fatalf("expecting 1 data container, got %v", n)
	}

	do := def.NowDo()
	do.Name = servName
	do.Operations.Args = []string{servName}
	do.Force = true
	do.File = false
	do.RmD = true
	if err := RmService(do); err != nil {
		t.Fatalf("expected service to be removed, got %v", err)
	}

	if n := util.HowManyContainersRunning(servName, def.TypeService); n != 0 {
		t.Fatalf("expecting 0 running service container, got %v", n)
	}
	if n := util.HowManyContainersExisting(servName, def.TypeService); n != 0 {
		t.Fatalf("expecting 0 existing service container, got %v", n)
	}
	if n := util.HowManyContainersExisting(servName, def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data container, got %v", n)
	}
}
Beispiel #4
0
func TestNewService(t *testing.T) {
	defer tests.RemoveAllContainers()

	do := def.NowDo()
	servName := "keys"
	do.Name = servName
	do.Operations.Args = []string{path.Join(ver.ERIS_REG_DEF, ver.ERIS_IMG_KEYS)}
	if err := NewService(do); err != nil {
		t.Fatalf("expected a new service to be created, got %v", err)
	}

	do = def.NowDo()
	do.Operations.Args = []string{servName}
	if err := StartService(do); err != nil {
		t.Fatalf("expected service to be started, got %v", err)
	}

	if n := util.HowManyContainersRunning(servName, def.TypeService); n != 1 {
		t.Fatalf("expecting 1 running service container, got %v", n)
	}
	if n := util.HowManyContainersExisting(servName, def.TypeData); n != 1 {
		t.Fatalf("expecting 1 data container, got %v", n)
	}

	kill(t, servName, true)
	if n := util.HowManyContainersExisting(servName, def.TypeService); n != 0 {
		t.Fatalf("expecting 0 service containers, got %v", n)
	}
	if n := util.HowManyContainersExisting(servName, def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data container, got %v", n)
	}

}
Beispiel #5
0
func TestChainsNewDirGenCustomFile(t *testing.T) {
	defer tests.RemoveAllContainers()

	const (
		chain    = "test-dir-gen"
		file     = "file.file"
		contents = "test contents"
	)

	dir := filepath.Join(common.DataContainersPath, chain)
	if err := os.MkdirAll(dir, 0700); err != nil {
		t.Fatalf("could not create a directory %q: %v", dir, err)
	}
	if err := tests.FakeDefinitionFile(filepath.Join(common.DataContainersPath, chain), file, contents); err != nil {
		t.Fatalf("could not create a test file %q: %v", file, err)
	}

	do := def.NowDo()
	do.GenesisFile = filepath.Join(common.ChainsPath, "default", "genesis.json")
	do.Name = chain
	do.Path = dir
	do.Operations.ContainerNumber = 1
	do.Operations.PublishAllPorts = true
	if err := NewChain(do); err != nil {
		t.Fatalf("expected a new chain to be created, got %v", err)
	}

	args := []string{"cat", filepath.Join(common.ErisContainerRoot, file+".toml")}
	if out := exec(t, chain, args); out != contents {
		t.Fatalf("expected file contents, got %q", out)
	}
}
Beispiel #6
0
func TestServiceLinkKeys(t *testing.T) {
	defer tests.RemoveAllContainers()

	do := def.NowDo()
	do.Name = chainName
	do.Operations.ContainerNumber = 1
	if err := NewChain(do); err != nil {
		t.Fatalf("could not start a new chain, got %v", err)
	}

	if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 test chain containers, got %v", n)
	}

	do = def.NowDo()
	do.Operations.Args = []string{"keys"}
	do.Operations.ContainerNumber = 1
	do.ChainName = chainName
	if err := services.StartService(do); err != nil {
		t.Fatalf("expecting service to start, got %v", err)
	}

	if n := util.HowManyContainersExisting("keys", def.TypeService); n != 1 {
		t.Fatalf("expecting 1 test chain containers, got %v", n)
	}

	links := tests.Links("keys", def.TypeService, 1)
	if len(links) != 0 {
		t.Fatalf("expected service links be empty, got %v", links)
	}
}
Beispiel #7
0
func TestServiceLinkWithDataContainer(t *testing.T) {
	defer tests.RemoveAllContainers()

	do := def.NowDo()
	do.Name = chainName
	do.Operations.ContainerNumber = 1
	if err := NewChain(do); err != nil {
		t.Fatalf("could not start a new chain, got %v", err)
	}

	if err := tests.FakeServiceDefinition(erisDir, "fake", `
chain = "$chain:fake"

[service]
name = "fake"
image = "`+path.Join(ver.ERIS_REG_DEF, ver.ERIS_IMG_IPFS)+`"
data_container = true
`); err != nil {
		t.Fatalf("can't create a fake service definition: %v", err)
	}

	if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 test chain containers, got %v", n)
	}

	if n := util.HowManyContainersExisting("fake", def.TypeService); n != 0 {
		t.Fatalf("expecting 0 service containers, got %v", n)
	}
	if n := util.HowManyContainersExisting("fake", def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data containers, got %v", n)
	}

	do = def.NowDo()
	do.Operations.Args = []string{"fake"}
	do.Operations.ContainerNumber = 1
	do.ChainName = chainName
	if err := services.StartService(do); err != nil {
		t.Fatalf("expecting service to start, got %v", err)
	}

	if n := util.HowManyContainersRunning("fake", def.TypeService); n != 1 {
		t.Fatalf("expecting 1 service containers, got %v", n)
	}
	if n := util.HowManyContainersExisting("fake", def.TypeData); n != 1 {
		t.Fatalf("expecting 1 data containers, got %v", n)
	}

	links := tests.Links("fake", def.TypeService, 1)
	if len(links) != 1 || !strings.Contains(links[0], chainName) {
		t.Fatalf("expected service be linked to a test chain, got %v", links)
	}
}
Beispiel #8
0
func TestInspectChain(t *testing.T) {
	defer tests.RemoveAllContainers()

	start(t, chainName)

	do := def.NowDo()
	do.Name = chainName
	do.Operations.Args = []string{"name"}
	do.Operations.ContainerNumber = 1
	if err := InspectChain(do); err != nil {
		t.Fatalf("expected chain to be inspected, got %v", err)
	}
}
Beispiel #9
0
func TestLogsChain(t *testing.T) {
	defer tests.RemoveAllContainers()

	start(t, chainName)

	do := def.NowDo()
	do.Name = chainName
	do.Follow = false
	do.Tail = "all"
	if err := LogsChain(do); err != nil {
		t.Fatalf("failed to fetch container logs")
	}
}
Beispiel #10
0
func TestRenameService(t *testing.T) {
	defer tests.RemoveAllContainers()

	start(t, "keys", false)
	if n := util.HowManyContainersRunning("keys", def.TypeService); n != 1 {
		t.Fatalf("#1. expecting 1 running service container, got %v", n)
	}
	if n := util.HowManyContainersExisting("keys", def.TypeData); n != 1 {
		t.Fatalf("#1. expecting 1 data container, got %v", n)
	}

	do := def.NowDo()
	do.Name = "keys"
	do.NewName = "syek"
	if err := RenameService(do); err != nil {
		t.Fatalf("expected service to be renamed, got %v", err)
	}

	if n := util.HowManyContainersRunning("keys", def.TypeService); n != 0 {
		t.Fatalf("#2. expecting 0 running service container, got %v", n)
	}
	if n := util.HowManyContainersExisting("keys", def.TypeData); n != 0 {
		t.Fatalf("#2. expecting 0 data container, got %v", n)
	}
	if n := util.HowManyContainersRunning("syek", def.TypeService); n != 1 {
		t.Fatalf("#3. expecting 1 running service container, got %v", n)
	}
	if n := util.HowManyContainersExisting("syek", def.TypeData); n != 1 {
		t.Fatalf("#3. expecting 1 data container, got %v", n)
	}

	do = def.NowDo()
	do.Name = "syek"
	do.NewName = "keys"
	if err := RenameService(do); err != nil {
		t.Fatalf("expected service to be renamed back, got %v", err)
	}

	if n := util.HowManyContainersRunning("syek", def.TypeService); n != 0 {
		t.Fatalf("#4. expecting 0 running service container, got %v", n)
	}
	if n := util.HowManyContainersExisting("syek", def.TypeData); n != 0 {
		t.Fatalf("#4. expecting 0 data container, got %v", n)
	}
	if n := util.HowManyContainersRunning("keys", def.TypeService); n != 1 {
		t.Fatalf("#5. expecting 1 running service container, got %v", n)
	}
	if n := util.HowManyContainersExisting("keys", def.TypeData); n != 1 {
		t.Fatalf("#5. expecting 1 data container, got %v", n)
	}
}
Beispiel #11
0
func TestInspectService2(t *testing.T) {
	defer tests.RemoveAllContainers()

	start(t, servName, false)

	do := def.NowDo()
	do.Name = servName
	do.Operations.Args = []string{"config.user"}
	do.Operations.ContainerNumber = 1

	if err := InspectService(do); err != nil {
		t.Fatalf("expected service to be inspected, got %v", err)
	}
}
Beispiel #12
0
func TestLogsService(t *testing.T) {
	defer tests.RemoveAllContainers()

	start(t, servName, false)

	do := def.NowDo()
	do.Name = servName
	do.Follow = false
	do.Tail = "5"

	if err := LogsService(do); err != nil {
		t.Fatalf("expected service to return logs, got %v", err)
	}
}
Beispiel #13
0
func TestExecServiceBadCommandLine(t *testing.T) {
	defer tests.RemoveAllContainers()

	start(t, servName, true)

	buf := new(bytes.Buffer)
	config.GlobalConfig.Writer = buf

	do := def.NowDo()
	do.Name = servName
	do.Operations.Interactive = false
	do.Operations.Args = strings.Fields("bad command line")

	if err := ExecService(do); err == nil {
		t.Fatal("expected executing service to fail")
	}
}
Beispiel #14
0
func TestUpdateChain(t *testing.T) {
	defer tests.RemoveAllContainers()

	start(t, chainName)

	do := def.NowDo()
	do.Name = chainName
	do.Pull = false
	do.Operations.PublishAllPorts = true
	if err := UpdateChain(do); err != nil {
		t.Fatalf("expected chain to update, got %v", err)
	}

	if n := util.HowManyContainersRunning(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 chain container running, got %v", n)
	}
}
Beispiel #15
0
func TestUpdateService(t *testing.T) {
	defer tests.RemoveAllContainers()

	start(t, servName, false)

	do := def.NowDo()
	do.Name = servName
	do.Pull = false
	do.Timeout = 1
	if err := UpdateService(do); err != nil {
		t.Fatalf("expected service to be updated, got %v", err)
	}

	if n := util.HowManyContainersRunning(servName, def.TypeService); n != 1 {
		t.Fatalf("expecting 1 running service container, got %v", n)
	}
}
Beispiel #16
0
func TestRestartChain(t *testing.T) {
	defer tests.RemoveAllContainers()

	do := def.NowDo()
	do.ConfigFile = filepath.Join(common.ChainsPath, "default", "config.toml")
	do.Name = chainName
	do.Operations.ContainerNumber = 1
	do.Operations.PublishAllPorts = true
	if err := NewChain(do); err != nil {
		t.Fatalf("expected a new chain to be created, got %v", err)
	}

	if n := util.HowManyContainersRunning(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 chain container, got %v", n)
	}
	if n := util.HowManyContainersExisting(chainName, def.TypeData); n != 1 {
		t.Fatalf("expecting 1 data containers, got %v", n)
	}

	kill(t, chainName)
	if n := util.HowManyContainersRunning(chainName, def.TypeChain); n != 0 {
		t.Fatalf("expecting 0 chain container, got %v", n)
	}
	if n := util.HowManyContainersExisting(chainName, def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data containers, got %v", n)
	}

	start(t, chainName)
	if n := util.HowManyContainersRunning(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 chain container, got %v", n)
	}
	if n := util.HowManyContainersExisting(chainName, def.TypeData); n != 1 {
		t.Fatalf("expecting 1 data containers, got %v", n)
	}

	kill(t, chainName)
	if n := util.HowManyContainersRunning(chainName, def.TypeChain); n != 0 {
		t.Fatalf("expecting 0 chain container, got %v", n)
	}
	if n := util.HowManyContainersExisting(chainName, def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data containers, got %v", n)
	}
}
Beispiel #17
0
func TestStartChain(t *testing.T) {
	defer tests.RemoveAllContainers()

	start(t, chainName)
	if n := util.HowManyContainersRunning(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 chain container, got %v", n)
	}
	if n := util.HowManyContainersExisting(chainName, def.TypeData); n != 1 {
		t.Fatalf("expecting 1 data containers, got %v", n)
	}

	kill(t, chainName)
	if n := util.HowManyContainersRunning(chainName, def.TypeChain); n != 0 {
		t.Fatalf("expecting 0 chain container, got %v", n)
	}
	if n := util.HowManyContainersExisting(chainName, def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data containers, got %v", n)
	}
}
Beispiel #18
0
func TestChainsNewDirGenesis(t *testing.T) {
	defer tests.RemoveAllContainers()

	const (
		chain = "test-dir-gen"
	)

	do := def.NowDo()
	do.Name = chain
	do.Operations.ContainerNumber = 1
	do.Operations.PublishAllPorts = true
	if err := NewChain(do); err != nil {
		t.Fatalf("expected a new chain to be created, got %v", err)
	}

	args := []string{"cat", fmt.Sprintf("/home/eris/.eris/chains/%s/genesis.json", chain)}
	if out := exec(t, chain, args); !strings.Contains(out, chain) {
		t.Fatalf("expected chain_id to be equal to chain name in genesis file, got %v", out)
	}
}
Beispiel #19
0
func TestStartKillService(t *testing.T) {
	defer tests.RemoveAllContainers()

	start(t, servName, false)
	if n := util.HowManyContainersRunning(servName, def.TypeService); n != 1 {
		t.Fatalf("expecting 1 running service container, got %v", n)
	}
	if n := util.HowManyContainersExisting(servName, def.TypeData); n != 1 {
		t.Fatalf("expecting 1 data container, got %v", n)
	}

	kill(t, servName, true)
	if n := util.HowManyContainersRunning(servName, def.TypeService); n != 0 {
		t.Fatalf("expecting 0 running service container, got %v", n)
	}
	if n := util.HowManyContainersExisting(servName, def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data container, got %v", n)
	}

}
Beispiel #20
0
func TestChainsNewCSV(t *testing.T) {
	defer tests.RemoveAllContainers()
	const (
		chain = "test-config-csv"
	)

	do := def.NowDo()
	do.Name = chain
	do.CSV = filepath.Join(common.ChainsPath, "default", "genesis.csv")
	do.Operations.ContainerNumber = 1
	do.Operations.PublishAllPorts = true
	if err := NewChain(do); err != nil {
		t.Fatalf("expected to create a new chain, got %v", err)
	}

	args := []string{"cat", fmt.Sprintf("/home/eris/.eris/chains/%s/genesis.json", chain)}
	if out := exec(t, chain, args); !strings.Contains(out, ini.DefaultPubKeys[0]) {
		t.Fatalf("expected to find a validator from csv, got %v", out)
	}

}
Beispiel #21
0
func TestChainsNewConfig(t *testing.T) {
	defer tests.RemoveAllContainers()
	const (
		chain = "test-config-csv"
	)

	do := def.NowDo()
	do.Name = chain
	do.ConfigFile = filepath.Join(common.ChainsPath, "default", "config.toml")
	do.CSV = filepath.Join(common.ChainsPath, "default", "genesis.csv")
	do.Operations.ContainerNumber = 1
	do.Operations.PublishAllPorts = true
	if err := NewChain(do); err != nil {
		t.Fatalf("expected to create a new chain, got %v", err)
	}

	args := []string{"cat", fmt.Sprintf("/home/eris/.eris/chains/%s/config.toml", chain)}
	if out := exec(t, chain, args); !strings.Contains(out, "defaulttester.com") {
		t.Fatalf("expected the config file to contain an expected string, got %v", out)
	}
}
Beispiel #22
0
func TestExecService(t *testing.T) {
	defer tests.RemoveAllContainers()

	start(t, servName, true)

	buf := new(bytes.Buffer)
	config.GlobalConfig.Writer = buf

	do := def.NowDo()
	do.Name = servName
	do.Operations.Interactive = false
	do.Operations.Args = strings.Fields("ls -la /root/")

	if err := ExecService(do); err != nil {
		t.Fatalf("expected to execute service, got %v", err)
	}

	if out := buf.String(); !strings.Contains(out, ".bashrc") {
		t.Fatalf("expected a file in the exec output, got %v", out)
	}
}
Beispiel #23
0
func TestServiceLinkBadChain(t *testing.T) {
	defer tests.RemoveAllContainers()

	if err := tests.FakeServiceDefinition(erisDir, "fake", `
chain = "$chain:fake"

[service]
name = "fake"
image = "`+path.Join(ver.ERIS_REG_DEF, ver.ERIS_IMG_IPFS)+`"
`); err != nil {
		t.Fatalf("can't create a fake service definition: %v", err)
	}

	do := def.NowDo()
	do.Operations.Args = []string{"fake"}
	do.Operations.ContainerNumber = 1
	do.ChainName = "non-existent-chain"
	if err := services.StartService(do); err == nil {
		t.Fatalf("expect start service to fail, got nil")
	}
}
Beispiel #24
0
func TestServiceLinkBadLiteral(t *testing.T) {
	defer tests.RemoveAllContainers()

	do := def.NowDo()
	do.Name = chainName
	do.Operations.ContainerNumber = 1
	if err := NewChain(do); err != nil {
		t.Fatalf("could not start a new chain, got %v", err)
	}

	if err := tests.FakeServiceDefinition(erisDir, "fake", `
chain = "blah-blah:blah"

[service]
name = "fake"
image = "`+path.Join(ver.ERIS_REG_DEF, ver.ERIS_IMG_IPFS)+`"
`); err != nil {
		t.Fatalf("can't create a fake service definition: %v", err)
	}

	if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 test chain containers, got %v", n)
	}

	do = def.NowDo()
	do.Operations.Args = []string{"fake"}
	do.Operations.ContainerNumber = 1
	do.ChainName = chainName
	// [pv]: probably a bug. Bad literal chain link in a definition
	// file doesn't affect the service start. Links is not nil.
	if err := services.StartService(do); err != nil {
		t.Fatalf("expecting service to start, got %v", err)
	}

	links := tests.Links("fake", def.TypeService, 1)
	if len(links) != 1 || !strings.Contains(links[0], chainName) {
		t.Fatalf("expected service be linked to a test chain, got %v", links)
	}
}
Beispiel #25
0
func TestStartKillServiceWithDependencies(t *testing.T) {
	defer tests.RemoveAllContainers()

	do := def.NowDo()
	do.Operations.Args = []string{"do_not_use"}
	if err := StartService(do); err != nil {
		t.Fatalf("expected service to start, got %v", err)
	}

	if n := util.HowManyContainersRunning(servName, def.TypeService); n != 1 {
		t.Fatalf("expecting 1 running service container, got %v", n)
	}
	if n := util.HowManyContainersExisting(servName, def.TypeData); n != 1 {
		t.Fatalf("expecting 1 data container, got %v", n)
	}
	if n := util.HowManyContainersRunning("keys", def.TypeService); n != 1 {
		t.Fatalf("expecting 1 running dependent service container, got %v", n)
	}
	if n := util.HowManyContainersExisting("keys", def.TypeData); n != 1 {
		t.Fatalf("expecting 1 dependent data container, got %v", n)
	}

	kill(t, "do_not_use", true)

	if n := util.HowManyContainersRunning(servName, def.TypeService); n != 0 {
		t.Fatalf("expecting 0 running service container, got %v", n)
	}
	if n := util.HowManyContainersExisting(servName, def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data container, got %v", n)
	}
	if n := util.HowManyContainersRunning("keys", def.TypeService); n != 0 {
		t.Fatalf("expecting 0 running dependent service container, got %v", n)
	}
	if n := util.HowManyContainersExisting("keys", def.TypeData); n != 0 {
		t.Fatalf("expecting 0 dependent data container, got %v", n)
	}
}
Beispiel #26
0
func TestCatChainContainerGenesis(t *testing.T) {
	defer tests.RemoveAllContainers()

	buf := new(bytes.Buffer)
	config.GlobalConfig.Writer = buf

	do := def.NowDo()
	do.ConfigFile = filepath.Join(common.ChainsPath, "default", "config.toml")
	do.Name = chainName
	do.Operations.ContainerNumber = 1
	do.Operations.PublishAllPorts = true
	if err := NewChain(do); err != nil {
		t.Fatalf("expected a new chain to be created, got %v", err)
	}

	do.Type = "genesis"
	if err := CatChain(do); err != nil {
		t.Fatalf("expected getting a local config to succeed, got %v", err)
	}

	if !strings.Contains(buf.String(), "accounts") || !strings.Contains(buf.String(), "validators") {
		t.Fatalf("expected the genesis file to contain expected strings, got %v", buf.String())
	}
}
Beispiel #27
0
func TestRenameChain(t *testing.T) {
	defer tests.RemoveAllContainers()

	const (
		chain   = "hichain"
		rename1 = "niahctset"
	)

	do := def.NowDo()
	do.Name = chain
	do.Operations.ContainerNumber = 1
	if err := NewChain(do); err != nil {
		t.Fatalf("expected a new chain to be created, got %v", err)
	}

	if n := util.HowManyContainersRunning(chain, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 chain container, got %v", n)
	}
	if n := util.HowManyContainersExisting(chain, def.TypeData); n != 1 {
		t.Fatalf("expecting 1 data containers, got %v", n)
	}

	do = def.NowDo()
	do.Name = chain
	do.NewName = rename1
	if err := RenameChain(do); err != nil {
		t.Fatalf("expected chain to be renamed #1, got %v", err)
	}

	if n := util.HowManyContainersRunning(chain, def.TypeChain); n != 0 {
		t.Fatalf("expecting 0 chain container, got %v", n)
	}
	if n := util.HowManyContainersExisting(chain, def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data containers, got %v", n)
	}

	if n := util.HowManyContainersRunning(rename1, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 chain container, got %v", n)
	}
	if n := util.HowManyContainersExisting(rename1, def.TypeData); n != 1 {
		t.Fatalf("expecting 1 data containers, got %v", n)
	}

	do = def.NowDo()
	do.Name = rename1
	do.NewName = chainName
	if err := RenameChain(do); err != nil {
		t.Fatalf("expected chain to be renamed #2, got %v", err)
	}

	if n := util.HowManyContainersRunning(rename1, def.TypeChain); n != 0 {
		t.Fatalf("expecting 0 chain container, got %v", n)
	}
	if n := util.HowManyContainersExisting(rename1, def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data containers, got %v", n)
	}

	if n := util.HowManyContainersRunning(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 chain container, got %v", n)
	}
	if n := util.HowManyContainersExisting(chainName, def.TypeData); n != 1 {
		t.Fatalf("expecting 1 data containers, got %v", n)
	}
}
Beispiel #28
0
func TestServiceLinkChainedService(t *testing.T) {
	defer tests.RemoveAllContainers()

	do := def.NowDo()
	do.Name = chainName
	do.Operations.ContainerNumber = 1
	if err := NewChain(do); err != nil {
		t.Fatalf("could not start a new chain, got %v", err)
	}

	if err := tests.FakeServiceDefinition(erisDir, "fake", `
chain = "$chain:fake"

[service]
name = "fake"
image = "`+path.Join(ver.ERIS_REG_DEF, ver.ERIS_IMG_IPFS)+`"

[dependencies]
services = [ "sham" ]
`); err != nil {
		t.Fatalf("can't create a fake service definition: %v", err)
	}

	if err := tests.FakeServiceDefinition(erisDir, "sham", `
chain = "$chain:sham"

[service]
name = "sham"
image = "`+path.Join(ver.ERIS_REG_DEF, ver.ERIS_IMG_KEYS)+`"
data_container = true
`); err != nil {
		t.Fatalf("can't create a sham service definition: %v", err)
	}

	if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 test chain containers, got %v", n)
	}

	do = def.NowDo()
	do.Operations.Args = []string{"fake"}
	do.Operations.ContainerNumber = 1
	do.ChainName = chainName
	if err := services.StartService(do); err != nil {
		t.Fatalf("expecting service to start, got %v", err)
	}

	if n := util.HowManyContainersRunning("fake", def.TypeService); n != 1 {
		t.Fatalf("expecting 1 fake service containers, got %v", n)
	}
	if n := util.HowManyContainersExisting("fake", def.TypeData); n != 0 {
		t.Fatalf("expecting 0 fake data containers, got %v", n)
	}
	if n := util.HowManyContainersRunning("sham", def.TypeService); n != 1 {
		t.Fatalf("expecting 1 sham service containers, got %v", n)
	}
	if n := util.HowManyContainersExisting("sham", def.TypeData); n != 1 {
		t.Fatalf("expecting 1 sham data containers, got %v", n)
	}

	// [pv]: second service doesn't reference the chain.
	links := tests.Links("fake", def.TypeService, 1)
	if len(links) != 2 || (!strings.Contains(links[1], chainName) && !strings.Contains(links[0], chainName)) {
		t.Fatalf("expected service be linked to a test chain, got %v", links)
	}
}