Exemplo n.º 1
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)
	}
}
Exemplo n.º 2
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)
	}
}
Exemplo n.º 3
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)
	}
}
Exemplo n.º 4
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)
	}
}