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) } }
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) } }
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") } }
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) } }
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) } }