本文整理匯總了Golang中github.com/eris-ltd/eris-cli/loaders.LoadServiceDefinition函數的典型用法代碼示例。如果您正苦於以下問題:Golang LoadServiceDefinition函數的具體用法?Golang LoadServiceDefinition怎麽用?Golang LoadServiceDefinition使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了LoadServiceDefinition函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestRunServiceNoDataContainer
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()
}
示例2: TestLoadServiceDefinition
func TestLoadServiceDefinition(t *testing.T) {
var e error
srv, e = loaders.LoadServiceDefinition(servName, true, 1)
if e != nil {
log.Error(e)
tests.IfExit(e)
}
if srv.Name != servName {
log.WithFields(log.Fields{
"expected": servName,
"got": srv.Name,
}).Error("Improper name on load")
}
if srv.Service.Name != servName {
log.WithFields(log.Fields{
"expected": servName,
"got": srv.Service.Name,
}).Error("Improper service name on load")
tests.IfExit(e)
}
if !srv.Service.AutoData {
log.Error("data_container not properly read on load")
tests.IfExit(e)
}
if srv.Operations.DataContainerName == "" {
log.Error("data_container_name not set")
tests.IfExit(e)
}
}
示例3: RmService
func RmService(do *definitions.Do) error {
for _, servName := range do.Args {
service, err := loaders.LoadServiceDefinition(servName, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
if IsServiceExisting(service.Service, service.Operations) {
err = perform.DockerRemove(service.Service, service.Operations, do.RmD)
if err != nil {
return err
}
}
if do.File {
oldFile := util.GetFileByNameAndType("services", servName)
if err != nil {
return err
}
oldFile = path.Join(ServicesPath, oldFile) + ".toml"
logger.Printf("Removing file =>\t\t%s\n", oldFile)
if err := os.Remove(oldFile); err != nil {
return err
}
}
}
do.Result = "success"
return nil
}
示例4: TestLoadServiceDefinition
func TestLoadServiceDefinition(t *testing.T) {
var e error
srv, e = loaders.LoadServiceDefinition(servName, true, 1)
if e != nil {
logger.Errorln(e)
tests.IfExit(e)
}
if srv.Name != servName {
logger.Errorf("FAILURE: improper name on LOAD. expected: %s\tgot: %s\n", servName, srv.Name)
}
if srv.Service.Name != servName {
logger.Errorf("FAILURE: improper service name on LOAD. expected: %s\tgot: %s\n", servName, srv.Service.Name)
tests.IfExit(e)
}
if !srv.Service.AutoData {
logger.Errorf("FAILURE: data_container not properly read on LOAD.\n")
tests.IfExit(e)
}
if srv.Operations.DataContainerName == "" {
logger.Errorf("FAILURE: data_container_name not set.\n")
tests.IfExit(e)
}
}
示例5: TestStopDataContainer
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()
}
示例6: LogsService
func LogsService(do *definitions.Do) error {
service, err := loaders.LoadServiceDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
return LogsServiceByService(service.Service, service.Operations, do.Follow, do.Tail)
}
示例7: TestDataContainerExistsAfterRemove
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()
}
示例8: ImportService
func ImportService(do *definitions.Do) error {
fileName := filepath.Join(ServicesPath, do.Name)
if filepath.Ext(fileName) == "" {
fileName = fileName + ".toml"
}
var err error
if logger.Level > 0 {
err = ipfs.GetFromIPFS(do.Hash, fileName, "", logger.Writer)
} else {
err = ipfs.GetFromIPFS(do.Hash, fileName, "", bytes.NewBuffer([]byte{}))
}
if err != nil {
return err
//return fmt.Errorf("I do not know how to get that file. Sorry. %v\n", err)
}
_, err = loaders.LoadServiceDefinition(do.Name, false, 0)
//XXX add protections?
if err != nil {
return fmt.Errorf("Your service defintion file looks improperly formatted and will not marshal.")
}
do.Result = "success"
return nil
}
示例9: TestContainerRunningBadName
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()
}
示例10: TestExecServiceAfterRunServiceWithPublishedPorts2
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()
}
示例11: TestExecServiceAfterRunService
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()
}
示例12: ExecService
func ExecService(do *definitions.Do) error {
service, err := loaders.LoadServiceDefinition(do.Name, false, do.Operations.ContainerNumber)
if err != nil {
return err
}
util.Merge(service.Operations, do.Operations)
// Get the main service container name, check if it's running.
main := util.FindServiceContainer(do.Name, do.Operations.ContainerNumber, false)
if main != nil {
if service.Service.ExecHost == "" {
log.Info("exec_host not found in service definition file")
log.WithField("service", do.Name).Info("May not be able to communicate with the service")
} else {
service.Service.Environment = append(service.Service.Environment,
fmt.Sprintf("%s=%s", service.Service.ExecHost, do.Name))
}
// Use service's short name as a link alias.
service.Service.Links = append(service.Service.Links, fmt.Sprintf("%s:%s", main.FullName, do.Name))
}
// Override links on the command line.
if len(do.Links) > 0 {
service.Service.Links = do.Links
}
return perform.DockerExecService(service.Service, service.Operations)
}
示例13: ImportService
func ImportService(do *definitions.Do) error {
fileName := filepath.Join(ServicesPath, do.Name)
if filepath.Ext(fileName) == "" {
fileName = fileName + ".toml"
}
var err error
if log.GetLevel() > 0 {
err = ipfs.GetFromIPFS(do.Hash, fileName, "", os.Stdout)
} else {
err = ipfs.GetFromIPFS(do.Hash, fileName, "", bytes.NewBuffer([]byte{}))
}
if err != nil {
return err
}
_, err = loaders.LoadServiceDefinition(do.Name, false, 0)
//XXX add protections?
if err != nil {
return fmt.Errorf("Your service definition file looks improperly formatted and will not marshal.")
}
do.Result = "success"
return nil
}
示例14: TestChainGraduate
func TestChainGraduate(t *testing.T) {
do := def.NowDo()
do.Name = chainName
if err := GraduateChain(do); err != nil {
t.Fatalf("expected chain to graduate, got %v", err)
}
srvDef, err := loaders.LoadServiceDefinition(chainName, false, 1)
if err != nil {
t.Fatalf("expected service definition to be loaded")
}
if image := path.Join(ver.ERIS_REG_DEF, ver.ERIS_IMG_DB); srvDef.Service.Image != image {
t.Fatalf("bad image on graduate, expected %s, got: %s", image, srvDef.Service.Image)
}
if srvDef.Service.Command != loaders.ErisChainStart {
t.Fatalf("improper service command on graduate, expected %s, got %s", loaders.ErisChainStart, srvDef.Service.Command)
}
if !srvDef.Service.AutoData {
t.Fatalf("improper service autodata value on graduate, expected %t, got %t", true, srvDef.Service.AutoData)
}
if len(srvDef.Dependencies.Services) != 1 {
t.Fatalf("improper service deps on graduate, expected: [%q], got %s", "keys", srvDef.Dependencies.Services)
}
}
示例15: TestChainGraduate
func TestChainGraduate(t *testing.T) {
do := def.NowDo()
do.Name = chainName
logger.Infof("Graduate chain (from tests) =>\t%s\n", do.Name)
if err := GraduateChain(do); err != nil {
fatal(t, err)
}
srvDef, err := loaders.LoadServiceDefinition(chainName, false, 1)
if err != nil {
fatal(t, err)
}
image := "eris/erisdb:" + version.VERSION
if srvDef.Service.Image != image {
fatal(t, fmt.Errorf("FAILURE: improper service image on GRADUATE. expected: %s\tgot: %s\n", image, srvDef.Service.Image))
}
if srvDef.Service.Command != loaders.ErisChainStart {
fatal(t, fmt.Errorf("FAILURE: improper service command on GRADUATE. expected: %s\tgot: %s\n", loaders.ErisChainStart, srvDef.Service.Command))
}
if !srvDef.Service.AutoData {
fatal(t, fmt.Errorf("FAILURE: improper service autodata on GRADUATE. expected: %t\tgot: %t\n", true, srvDef.Service.AutoData))
}
if len(srvDef.Dependencies.Services) != 1 {
fatal(t, fmt.Errorf("FAILURE: improper service deps on GRADUATE. expected: [\"keys\"]\tgot: %s\n", srvDef.Dependencies.Services))
}
}