예제 #1
0
func testExistAndRun(t *testing.T, chainName string, toExist, toRun bool) {
	var exist, run bool
	logger.Infof("\nTesting whether (%s) is running? (%t) and existing? (%t)\n", chainName, toRun, toExist)
	chainName = util.ChainContainersName(chainName, 1) // not worried about containerNumbers, deal with multiple containers in services tests

	do := def.NowDo()
	do.Quiet = true
	do.Args = []string{"testing"}
	if err := ListExisting(do); err != nil {
		logger.Errorln(err)
		t.FailNow()
	}
	res := strings.Split(do.Result, "\n")
	for _, r := range res {
		logger.Debugf("Existing =>\t\t\t%s\n", r)
		if r == util.ContainersShortName(chainName) {
			exist = true
		}
	}

	do = def.NowDo()
	do.Quiet = true
	do.Args = []string{"testing"}
	if err := ListRunning(do); err != nil {
		logger.Errorln(err)
		t.FailNow()
	}
	res = strings.Split(do.Result, "\n")
	for _, r := range res {
		logger.Debugf("Running =>\t\t\t%s\n", r)
		if r == util.ContainersShortName(chainName) {
			run = true
		}
	}

	if toExist != exist {
		if toExist {
			logger.Infof("Could not find an existing =>\t%s\n", chainName)
		} else {
			logger.Infof("Found an existing instance of %s when I shouldn't have\n", chainName)
		}
		t.Fail()
	}

	if toRun != run {
		if toRun {
			logger.Infof("Could not find a running =>\t%s\n", chainName)
		} else {
			logger.Infof("Found a running instance of %s when I shouldn't have\n", chainName)
		}
		t.Fail()
	}

	logger.Debugln("")
}
예제 #2
0
func testExistAndRun(t *testing.T, servName string, containerNumber int, toExist, toRun bool) {
	var exist, run bool
	logger.Infof("\nTesting whether (%s) is running? (%t) and existing? (%t)\n", servName, toRun, toExist)
	servName = util.ServiceContainersName(servName, containerNumber)

	do := def.NowDo()
	do.Quiet = true
	do.Args = []string{"testing"}
	if err := ListExisting(do); err != nil {
		logger.Errorln(err)
		fatal(t, err)
	}
	res := strings.Split(do.Result, "\n")
	for _, r := range res {
		logger.Debugf("Existing =>\t\t\t%s\n", r)
		if r == util.ContainersShortName(servName) {
			exist = true
		}
	}

	do = def.NowDo()
	do.Quiet = true
	do.Args = []string{"testing"}
	if err := ListRunning(do); err != nil {
		logger.Errorln(err)
		fatal(t, err)
	}
	res = strings.Split(do.Result, "\n")
	for _, r := range res {
		logger.Debugf("Running =>\t\t\t%s\n", r)
		if r == util.ContainersShortName(servName) {
			run = true
		}
	}

	if toExist != exist {
		if toExist {
			logger.Printf("Could not find an existing =>\t%s\n", servName)
		} else {
			logger.Printf("Found an existing instance of %s when I shouldn't have\n", servName)
		}
		fatal(t, nil)
	}

	if toRun != run {
		if toRun {
			logger.Printf("Could not find a running =>\t%s\n", servName)
		} else {
			logger.Printf("Found a running instance of %s when I shouldn't have\n", servName)
		}
		fatal(t, nil)
	}

	logger.Infoln("All good.\n")
}
예제 #3
0
func testExist(t *testing.T, name string, toExist bool) {
	var exist bool
	logger.Infof("\nTesting whether (%s) existing? (%t)\n", name, toExist)
	name = util.DataContainersName(name, 1)

	do := definitions.NowDo()
	do.Quiet = true
	if err := ListKnown(do); err != nil {
		logger.Errorln(err)
		t.FailNow()
	}
	res := strings.Split(do.Result, "\n")
	for _, r := range res {
		logger.Debugf("Existing =>\t\t\t%s\n", r)
		if r == util.ContainersShortName(name) {
			exist = true
		}
	}

	if toExist != exist {
		if toExist {
			logger.Infof("Could not find an existing =>\t%s\n", name)
		} else {
			logger.Infof("Found an existing instance of %s when I shouldn't have\n", name)
		}
		t.Fail()
	}
}
예제 #4
0
//return to handle failings in each pkg
//typ = type of test for dealing with do.() details
func TestExistAndRun(name, typ string, contNum int, toExist, toRun bool) bool {
	var exist, run bool
	if typ == "actions" {
		name = strings.Replace(name, " ", "_", -1) // dirty
	}

	//logger.Infof("\nTesting whether (%s) existing? (%t)\n", name, toExist)
	logger.Infof("\nTesting whether (%s) is running? (%t) and existing? (%t)\n", name, toRun, toExist)
	if typ == "chains" {
		name = util.ChainContainersName(name, 1) // not worried about containerNumbers, deal with multiple containers in services tests
	} else if typ == "services" {
		name = util.ServiceContainersName(name, contNum)

	} else {
		name = util.DataContainersName(name, 1)
	}
	do := def.NowDo()
	do.Quiet = true
	do.Operations.Args = []string{"testing"}

	if typ == "data" || typ == "chains" || typ == "services" {
		do.Existing = true
	} else if typ == "actions" {
		do.Known = true
	}
	if err := util.ListAll(do, typ); err != nil {
		logger.Errorln(err)
		return true
	}

	res := strings.Split(do.Result, "\n")
	for _, r := range res {
		logger.Debugf("Existing =>\t\t\t%s\n", r)
		if r == util.ContainersShortName(name) {
			exist = true
		}
	}

	if toExist != exist {
		if toExist {
			logger.Infof("Could not find an existing =>\t%s\n", name)
		} else {
			logger.Infof("Found an existing instance of %s when I shouldn't have\n", name)
		}
		return true
	}
	//func should always be testing for toExist, only sometimes tested for runining
	if typ == "chains" || typ == "services" {
		do.Running = true
		do.Existing = false //unset
		if err := util.ListAll(do, typ); err != nil {
			return true
		}
		logger.Debugln("RUNNING RESULT:", do.Result)
		res = strings.Split(do.Result, "\n")
		for _, r := range res {
			logger.Debugf("Running =>\t\t\t%s\n", r)
			if r == util.ContainersShortName(name) {
				run = true
			}
		}

		if toRun != run {
			if toRun {
				logger.Infof("Could not find a running =>\t%s\n", name)
			} else {
				logger.Infof("Found a running instance of %s when I shouldn't have\n", name)
			}
			return true
		}
	}

	return false
}