コード例 #1
0
ファイル: services_test.go プロジェクト: antonylewis/eris-cli
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)
	}
}
コード例 #2
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestCreateDataSimple(t *testing.T) {
	const (
		name   = "testdata"
		number = 199
	)

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

	ops := loaders.LoadDataDefinition(name, number)
	if err := DockerCreateData(ops); err != nil {
		t.Fatalf("expected data container created, got %v", err)
	}

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

	// Try to create a duplicate.
	if err := DockerCreateData(ops); err == nil {
		t.Fatalf("expected an error, got nil")
	}

	tests.RemoveAllContainers()
}
コード例 #3
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestExecServiceAfterRunServiceWithPublishedPorts2(t *testing.T) {
	const (
		name   = "ipfs"
		number = 99
	)

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

	srv, err := loaders.LoadServiceDefinition(name, true, number)
	if err != nil {
		t.Fatalf("could not load service definition %v", err)
	}

	if err := DockerRunService(srv.Service, srv.Operations); err != nil {
		t.Fatalf("expected service container created, got %v", err)
	}

	srv.Operations.PublishAllPorts = true
	srv.Operations.Interactive = true
	srv.Operations.Args = []string{"uptime"}
	if err := DockerExecService(srv.Service, srv.Operations); err != nil {
		t.Fatalf("expected exec container created, got %v", err)
	}

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

	tests.RemoveAllContainers()
}
コード例 #4
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestExecServiceBadCommandLine(t *testing.T) {
	const (
		name   = "ipfs"
		number = 99
	)

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

	srv, err := loaders.LoadServiceDefinition(name, true, number)
	if err != nil {
		t.Fatalf("could not load service definition %v", err)
	}

	srv.Operations.Interactive = false
	srv.Operations.Args = []string{"/bad/command/line"}
	if err := DockerExecService(srv.Service, srv.Operations); err == nil {
		t.Fatalf("expected failure, got %v", err)
	}

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

	tests.RemoveAllContainers()
}
コード例 #5
0
ファイル: chains_test.go プロジェクト: mxjxn/eris-cli
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)
	}
}
コード例 #6
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestRunServiceNoDataContainer(t *testing.T) {
	const (
		name   = "ipfs"
		number = 99
	)

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

	srv, err := loaders.LoadServiceDefinition(name, true, number)
	if err != nil {
		t.Fatalf("could not load service definition %v", err)
	}

	srv.Service.AutoData = false
	if err := DockerRunService(srv.Service, srv.Operations); err != nil {
		t.Fatalf("expected service container created, got %v", err)
	}

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

	tests.RemoveAllContainers()
}
コード例 #7
0
ファイル: chains_test.go プロジェクト: antonylewis/eris-cli
func TestRmChain(t *testing.T) {
	start(t, chainName)

	do := def.NowDo()
	do.Operations.Args, do.Rm, do.RmD = []string{"keys"}, true, true
	if err := services.KillService(do); err != nil {
		t.Fatalf("expected service to be stopped, got %v", err)
	}

	do = def.NowDo()
	do.Name, do.Rm, do.RmD = chainName, false, false
	log.WithField("=>", do.Name).Info("Stopping chain (from tests)")
	if err := KillChain(do); err != nil {
		t.Fatalf("expected chain to be stopped, got %v", err)
	}
	if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 1 {
		t.Fatalf("expecting 1 chain containers, got %v", n)
	}

	do = def.NowDo()
	do.Name = chainName
	do.RmD = true
	log.WithField("=>", do.Name).Info("Removing chain (from tests)")
	if err := RmChain(do); err != nil {
		t.Fatalf("expected chain to be removed, got %v", err)
	}
	if n := util.HowManyContainersExisting(chainName, def.TypeChain); n != 0 {
		t.Fatalf("expecting 0 chain containers, got %v", n)
	}
}
コード例 #8
0
ファイル: services_test.go プロジェクト: antonylewis/eris-cli
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)
	}

}
コード例 #9
0
ファイル: chains_test.go プロジェクト: mxjxn/eris-cli
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 = "quay.io/eris/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)
	}
}
コード例 #10
0
ファイル: services_test.go プロジェクト: antonylewis/eris-cli
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)
	}
}
コード例 #11
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestRemoveWithoutData(t *testing.T) {
	const (
		name   = "ipfs"
		number = 99
	)

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

	srv, err := loaders.LoadServiceDefinition(name, true, number)
	if err != nil {
		t.Fatalf("could not load service definition %v", err)
	}

	if err := DockerRunService(srv.Service, srv.Operations); err != nil {
		t.Fatalf("expected service container created, got %v", err)
	}

	if err := DockerStop(srv.Service, srv.Operations, 5); err != nil {
		t.Fatal("expected service container stopped, got %v", err)
	}

	if n := util.HowManyContainersExisting(name, def.TypeService); n != 1 {
		t.Fatalf("expecting 1 service container running (before removal), got %v", n)
	}

	if err := DockerRemove(srv.Service, srv.Operations, false, true); err != nil {
		t.Fatal("expected service container removed, got %v", err)
	}

	if n := util.HowManyContainersExisting(name, def.TypeService); n != 0 {
		t.Fatalf("expecting 0 service container running (after removal), got %v", n)
	}

	srv.Operations.SrvContainerName = srv.Operations.DataContainerName
	if n := util.HowManyContainersExisting(name, def.TypeData); n != 1 {
		t.Fatalf("expecting 1 data container existing (before removal), got %v", n)
	}

	if err := DockerRemove(srv.Service, srv.Operations, false, true); err != nil {
		t.Fatal("expected service container removed, got %v", err)
	}

	if n := util.HowManyContainersExisting(name, def.TypeData); n != 0 {
		t.Fatalf("expecting 0 data container running (after removal), got %v", n)
	}

	tests.RemoveAllContainers()
}
コード例 #12
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestDataContainerExistsAfterRemove(t *testing.T) {
	const (
		name   = "ipfs"
		number = 99
	)

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

	srv, err := loaders.LoadServiceDefinition(name, true, number)
	if err != nil {
		t.Fatalf("could not load service definition %v", err)
	}

	if err := DockerRunService(srv.Service, srv.Operations); err != nil {
		t.Fatalf("expected service container created, got %v", err)
	}

	srv.Operations.SrvContainerName = srv.Operations.DataContainerName
	if _, exists := DataContainerExists(srv.Operations); exists == false {
		t.Fatalf("expecting service container exists, got false")
	}

	tests.RemoveContainer(name, def.TypeData, number)

	if _, exists := DataContainerExists(srv.Operations); exists == true {
		t.Fatalf("expecting service container not existing after remove, got true")
	}

	tests.RemoveAllContainers()
}
コード例 #13
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestContainerRunningBadName(t *testing.T) {
	const (
		name   = "ipfs"
		number = 99
	)

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

	srv, err := loaders.LoadServiceDefinition(name, true, number)
	if err != nil {
		t.Fatalf("could not load service definition %v", err)
	}

	if err := DockerRunService(srv.Service, srv.Operations); err != nil {
		t.Fatalf("expected service container created, got %v", err)
	}

	if _, exists := ContainerRunning(srv.Operations); exists == false {
		t.Fatalf("expecting service container running, got false")
	}

	srv.Operations.SrvContainerName = "random-bad-name"
	if _, exists := ContainerRunning(srv.Operations); exists == true {
		t.Fatalf("expecting data container not running, got true")
	}

	tests.RemoveAllContainers()
}
コード例 #14
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestExecServiceAfterRunService(t *testing.T) {
	const (
		name   = "ipfs"
		number = 99
	)

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

	srv, err := loaders.LoadServiceDefinition(name, true, number)
	if err != nil {
		t.Fatalf("could not load service definition %v", err)
	}

	if err := DockerRunService(srv.Service, srv.Operations); err != nil {
		t.Fatalf("expected service container created, got %v", err)
	}

	srv.Operations.Interactive = true
	srv.Operations.Args = []string{"uptime"}
	if err := DockerExecService(srv.Service, srv.Operations); err == nil {
		t.Fatalf("expected failure due to unpublished ports, got %v", err)
	}

	tests.RemoveAllContainers()
}
コード例 #15
0
ファイル: chains_test.go プロジェクト: mxjxn/eris-cli
func TestServiceLinkBadChainWithoutChainInDefinition(t *testing.T) {
	defer tests.RemoveAllContainers()

	if err := tests.FakeServiceDefinition(erisDir, "fake", `
[service]
name = "fake"
image = "quay.io/eris/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)
	}
}
コード例 #16
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestStopDataContainer(t *testing.T) {
	const (
		name   = "ipfs"
		number = 99
	)

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

	srv, err := loaders.LoadServiceDefinition(name, true, number)
	if err != nil {
		t.Fatalf("could not load service definition %v", err)
	}

	if err := DockerRunService(srv.Service, srv.Operations); err != nil {
		t.Fatalf("expected service container created, got %v", err)
	}

	srv.Operations.SrvContainerName = srv.Operations.DataContainerName
	if err := DockerStop(srv.Service, srv.Operations, 5); err == nil {
		t.Fatalf("expected stop to fail, got %v", err)
	}

	tests.RemoveAllContainers()
}
コード例 #17
0
ファイル: clean_test.go プロジェクト: antonylewis/eris-cli
//[zr] TODO move to testings package
func testNumbersExistAndRun(t *testing.T, servName string, containerExist, containerRun int) {
	log.WithFields(log.Fields{
		"=>":        servName,
		"existing#": containerExist,
		"running#":  containerRun,
	}).Info("Checking number of containers for")

	log.WithField("=>", servName).Debug("Checking existing containers for")
	exist := util.HowManyContainersExisting(servName, "service")

	log.WithField("=>", servName).Debug("Checking running containers for")
	run := util.HowManyContainersRunning(servName, "service")

	if exist != containerExist {
		log.WithFields(log.Fields{
			"name":     servName,
			"expected": containerExist,
			"got":      exist,
		}).Error("Wrong number of existing containers")
		fatal(t, nil)
	}

	if run != containerRun {
		log.WithFields(log.Fields{
			"name":     servName,
			"expected": containerExist,
			"got":      run,
		}).Error("Wrong number of running containers")
		fatal(t, nil)
	}

	log.Info("All good")
}
コード例 #18
0
ファイル: chains_test.go プロジェクト: antonylewis/eris-cli
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)
	}
}
コード例 #19
0
ファイル: chains_test.go プロジェクト: antonylewis/eris-cli
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)
	}
}
コード例 #20
0
ファイル: services_test.go プロジェクト: antonylewis/eris-cli
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)
	}

}
コード例 #21
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestRunServiceTwoServicesPublishedPorts(t *testing.T) {
	const (
		name   = "ipfs"
		number = 99
	)

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

	srv1, err := loaders.LoadServiceDefinition(name, true, number)
	if err != nil {
		t.Fatalf("1. could not load service definition %v", err)
	}

	if err := DockerRunService(srv1.Service, srv1.Operations); err != nil {
		t.Fatalf("1. expected service container created, got %v", err)
	}

	srv2, err := loaders.LoadServiceDefinition(name, true, number+1)
	if err != nil {
		t.Fatalf("2. could not load service definition %v", err)
	}

	srv2.Operations.PublishAllPorts = true
	if err := DockerRunService(srv2.Service, srv2.Operations); err != nil {
		t.Fatalf("2. expected service container created, got %v", err)
	}

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

	tests.RemoveAllContainers()
}
コード例 #22
0
ファイル: services_test.go プロジェクト: antonylewis/eris-cli
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)
	}
}
コード例 #23
0
ファイル: services_test.go プロジェクト: alexandrev/eris-cli
func testNumbersExistAndRun(t *testing.T, servName string, containerExist, containerRun int) {
	logger.Infof("\nTesting number of (%s) containers. Existing? (%d) and Running? (%d)\n", servName, containerExist, containerRun)

	logger.Debugf("Checking Existing Containers =>\t%s\n", servName)
	exist := util.HowManyContainersExisting(servName, "service")
	logger.Debugf("Checking Running Containers =>\t%s\n", servName)
	run := util.HowManyContainersRunning(servName, "service")

	if exist != containerExist {
		tests.IfExit(fmt.Errorf("Wrong number of containers existing for service (%s). Expected (%d). Got (%d).\n", servName, containerExist, exist))
	}

	if run != containerRun {
		tests.IfExit(fmt.Errorf("Wrong number of containers running for service (%s). Expected (%d). Got (%d).\n", servName, containerRun, run))
	}

	logger.Infoln("All good.\n")
}
コード例 #24
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestStopSimple(t *testing.T) {
	const (
		name   = "ipfs"
		number = 99
	)

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

	srv, err := loaders.LoadServiceDefinition(name, true, number)
	if err != nil {
		t.Fatalf("could not load service definition %v", err)
	}

	if err := DockerRunService(srv.Service, srv.Operations); err != nil {
		t.Fatalf("expected service container created, got %v", err)
	}

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

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

	if err := DockerStop(srv.Service, srv.Operations, 5); err != nil {
		t.Fatalf("expected service container to stop, got %v", err)
	}

	if n := util.HowManyContainersRunning(name, def.TypeService); n != 0 {
		t.Fatalf("expecting 0 service containers running (after stop), got %v", n)
	}

	if n := util.HowManyContainersRunning(name, def.TypeService); n != 0 {
		t.Fatalf("expecting 1 service containers existing (after stop), got %v", n)
	}

	tests.RemoveAllContainers()
}
コード例 #25
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestRunDataSimple(t *testing.T) {
	const (
		name   = "testdata"
		number = 199
	)

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

	ops := loaders.LoadDataDefinition(name, number)
	if err := DockerCreateData(ops); err != nil {
		t.Fatalf("expected data container created, got %v", err)
	}

	ops.Args = []string{"uptime"}
	if _, err := DockerRunData(ops, nil); err != nil {
		t.Fatalf("expected data successfully run, got %v", err)
	}

	tests.RemoveAllContainers()
}
コード例 #26
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestDataContainerExistsBadName(t *testing.T) {
	const (
		name   = "ipfs"
		number = 99
	)

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

	srv, err := loaders.LoadServiceDefinition(name, true, number)
	if err != nil {
		t.Fatalf("could not load service definition %v", err)
	}

	srv.Operations.SrvContainerName = "some-random-name"
	if _, exists := DataContainerExists(srv.Operations); exists != false {
		t.Fatalf("expecting service container not existing, got true")
	}

	tests.RemoveAllContainers()
}
コード例 #27
0
ファイル: perform_test.go プロジェクト: alexandrev/eris-cli
func TestRunDataBadCommandLine(t *testing.T) {
	const (
		name   = "testdata"
		number = 199
	)

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

	ops := loaders.LoadDataDefinition(name, number)
	if err := DockerCreateData(ops); err != nil {
		t.Fatalf("expected data container created, got %v", err)
	}

	ops.Args = []string{"/bad/command/line"}
	if _, err := DockerRunData(ops, nil); err == nil {
		t.Fatalf("expected command line error, got nil")
	}

	tests.RemoveAllContainers()
}
コード例 #28
0
ファイル: chains_test.go プロジェクト: mxjxn/eris-cli
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 = "quay.io/eris/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)
	}
}
コード例 #29
0
ファイル: services_test.go プロジェクト: mxjxn/eris-cli
func testNumbersExistAndRun(t *testing.T, servName string, containerExist, containerRun int) {
	log.WithFields(log.Fields{
		"=>":        servName,
		"existing#": containerExist,
		"running#":  containerRun,
	}).Info("Checking number of containers for")

	log.WithField("=>", servName).Debug("Checking existing containers for")
	exist := util.HowManyContainersExisting(servName, "service")

	log.WithField("=>", servName).Debug("Checking running containers for")
	run := util.HowManyContainersRunning(servName, "service")

	if exist != containerExist {
		tests.IfExit(fmt.Errorf("Wrong number of containers existing for service (%s). Expected (%d). Got (%d).\n", servName, containerExist, exist))
	}

	if run != containerRun {
		tests.IfExit(fmt.Errorf("Wrong number of containers running for service (%s). Expected (%d). Got (%d).\n", servName, containerRun, run))
	}

	log.Info("All good")
}
コード例 #30
0
ファイル: chains_test.go プロジェクト: mxjxn/eris-cli
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 = "quay.io/eris/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 = "quay.io/eris/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)
	}
}