Example #1
0
func TestListKnownActions(t *testing.T) {
	do := definitions.NowDo()
	do.Known = true
	do.Running = false
	do.Existing = false
	do.Operations.Args = []string{"testing"}
	tests.IfExit(util.ListAll(do, "actions"))
	k := strings.Split(do.Result, "\n") // tests output formatting.

	if len(k) != 4 {
		tests.IfExit(fmt.Errorf("Found %v action definition files, Expected 4. Something is wrong.\n", len(k)))
	}

	i := 0
	for _, actFile := range k {
		switch actFile {
		case "do_not_use":
			i++
		case "chain_info":
			i++
		case "dns_register":
			i++
		case "keys_list":
			i++
		}
	}
	if i != 4 {
		tests.IfExit(fmt.Errorf("Could not find all the expected action definition files.\n"))
	}
}
Example #2
0
func ListAllTheThings() {
	//do.All for known/existing/running
	do.All = true

	typs := []string{"services", "chains", "actions", "data"}
	for _, typ := range typs {
		if err := util.ListAll(do, typ); err != nil {
			return
		}
	}
}
Example #3
0
//----------------------------------------------------
func ListKnownData(cmd *cobra.Command, args []string) {
	do.Existing = true
	if err := util.ListAll(do, "data"); err != nil {
		return
	}

	// https://www.reddit.com/r/television/comments/2755ow/hbos_silicon_valley_tells_the_most_elaborate/
	datasToManipulate := do.Result
	for _, s := range strings.Split(datasToManipulate, "||") {
		fmt.Println(s)
	}
}
Example #4
0
func ListActions(cmd *cobra.Command, args []string) {
	// TODO: add scoping for when projects done.
	do.Known = true
	do.Running = false
	do.Existing = false
	if err := util.ListAll(do, "actions"); err != nil {
		return
	}
	for _, s := range strings.Split(do.Result, "\n") {
		log.Warn(strings.Replace(s, "_", " ", -1))
	}
}
Example #5
0
func _parseKnown(name string) bool {
	do := def.NowDo()
	do.Existing = true
	util.ListAll(do, "data")
	if len(do.Operations.Args) != 0 {
		for _, srv := range do.Operations.Args {
			if srv == name {
				return true
			}
		}
	}
	return false
}
Example #6
0
//------- helpers --------
func checkIPFSnotRunning() {
	//os.Setenv("ERIS_IPFS_HOST", "http://0.0.0.0") //conflicts with docker-machine
	do := def.NowDo()
	do.Known = false
	do.Existing = false
	do.Running = true
	do.Quiet = true
	do.Operations.Args = []string{"testing"}
	logger.Debugln("Finding the running services.")
	if err := util.ListAll(do, "services"); err != nil {
		IfExit(err)
	}
	res := strings.Split(do.Result, "\n")
	for _, r := range res {
		if r == "ipfs" {
			IfExit(fmt.Errorf("IPFS service is running.\nPlease stop it with.\neris services stop -rx ipfs\n"))
		}
	}
	// make sure ipfs container does not exist
	do = def.NowDo()
	do.Known = false
	do.Existing = true
	do.Running = false
	do.Quiet = true
	do.Operations.Args = []string{"testing"}
	logger.Debugln("Finding the existing services.")
	if err := util.ListAll(do, "services"); err != nil {
		IfExit(err)
	}
	res = strings.Split(do.Result, "\n")
	for _, r := range res {
		if r == "ipfs" {
			IfExit(fmt.Errorf("IPFS service exists.\nPlease remove it with\neris services rm ipfs\n"))
		}
	}
}
Example #7
0
func TestKnownChain(t *testing.T) {
	do := def.NowDo()
	do.Known = true
	do.Existing = false
	do.Running = false
	do.Operations.Args = []string{"testing"}
	tests.IfExit(util.ListAll(do, "chains"))

	k := strings.Split(do.Result, "\n") // tests output formatting.

	// apparently these have extra space
	if strings.TrimSpace(k[0]) != chainName {
		log.WithField("=>", do.Result).Debug("Result")
		tests.IfExit(fmt.Errorf("Unexpected chain definition file. Got %s, expected %s.", k[0], chainName))
	}
}
Example #8
0
func TestKnownServices(t *testing.T) {
	do := def.NowDo()
	do.Known = true
	do.Existing = false
	do.Running = false
	do.Operations.Args = []string{"testing"}
	tests.IfExit(util.ListAll(do, "services"))
	k := strings.Split(do.Result, "\n") // tests output formatting.

	if len(k) != 13 {
		tests.IfExit(fmt.Errorf("Did not find exactly 13 service definitions files, found %v. Something is wrong.\n", len(k)))
	}
	i := 0
	for _, actFile := range k {
		switch actFile {
		case "btcd":
			i++
		case "compilers":
			i++
		case "eth":
			i++
		case "ipfs":
			i++
		case "keys":
			i++
		case "logspout":
			i++
		case "logsrotate":
			i++
		case "mindy":
			i++
		case "mint":
			i++
		case "openbazaar":
			i++
		case "tinydns":
			i++
		case "watchtower":
			i++
		case "do_not_use":
			i++
		}
	}
	if i != 13 {
		tests.IfExit(fmt.Errorf("Could not find all the expected service definition files.\n"))
	}
}
Example #9
0
func TestListActions(t *testing.T) {
	do := definitions.NowDo()
	do.Known = true
	do.Running = false
	do.Existing = false
	do.Operations.Args = []string{"testing"}
	tests.IfExit(util.ListAll(do, "actions"))
	k := strings.Split(do.Result, "\n") // tests output formatting.

	if len(k) != 1 {
		tests.IfExit(fmt.Errorf("The wrong number of action definitions have been found. Something is wrong.\n"))
	}

	if k[0] != "do_not_use" {
		tests.IfExit(fmt.Errorf("Could not find \"do not use\" action definition.\n"))
	}
}
Example #10
0
func TestKnownService(t *testing.T) {
	do := def.NowDo()
	do.Known = true
	do.Existing = false
	do.Running = false
	do.Operations.Args = []string{"testing"}
	tests.IfExit(util.ListAll(do, "services"))
	k := strings.Split(do.Result, "\n") // tests output formatting.

	if len(k) != 3 {
		tests.IfExit(fmt.Errorf("Did not find exactly 3 service definitions files. Something is wrong.\n"))
	}

	if k[1] != "ipfs" {
		tests.IfExit(fmt.Errorf("Could not find ipfs service definition. Services found =>\t%v\n", k))
	}
}
Example #11
0
func ListAllChains(cmd *cobra.Command, args []string) {
	//if no flags are set, list all the things
	//otherwise, allow only a single flag
	if !(do.Known || do.Running || do.Existing) {
		do.All = true
	} else {
		flargs := []bool{do.Known, do.Running, do.Existing}
		flags := []string{}

		for _, f := range flargs {
			if f == true {
				flags = append(flags, "true")
			}
		}
		IfExit(FlagCheck(1, "eq", cmd, flags))
	}

	if err := util.ListAll(do, "chains"); err != nil {
		return
	}
	if !do.All { //do.All will output a pretty table on its own
		fmt.Println(do.Result)
	}
}
Example #12
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
}