run

package
v0.17.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2018 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "run",
	Short: "Run Tests",
	PreRun: func(cmd *cobra.Command, args []string) {

		if len(args) == 0 {
			path = append(path, ".")
		} else {
			path = args[0:]
		}

		v = venom.New()
		v.RegisterExecutor(exec.Name, exec.New())
		v.RegisterExecutor(http.Name, http.New())
		v.RegisterExecutor(imap.Name, imap.New())
		v.RegisterExecutor(readfile.Name, readfile.New())
		v.RegisterExecutor(smtp.Name, smtp.New())
		v.RegisterExecutor(ssh.Name, ssh.New())
		v.RegisterExecutor(web.Name, web.New())
		v.RegisterExecutor(ovhapi.Name, ovhapi.New())
		v.RegisterExecutor(dbfixtures.Name, dbfixtures.New())

		v.RegisterTestCaseContext(defaultctx.Name, defaultctx.New())
		v.RegisterTestCaseContext(webctx.Name, webctx.New())

	},
	Run: func(cmd *cobra.Command, args []string) {

		v.LogLevel = logLevel
		v.OutputDetails = detailsLevel
		v.OutputDir = outputDir
		v.OutputFormat = format
		v.OutputResume = resume
		v.OutputResumeFailures = resumeFailures
		v.Parallel = parallel

		mapvars := make(map[string]string)
		if withEnv {
			variables = append(variables, os.Environ()...)
		}

		for _, a := range variables {
			t := strings.SplitN(a, "=", 2)
			if len(t) < 2 {
				continue
			}
			mapvars[t[0]] = strings.Join(t[1:], "")
		}

		if varFile != "" {
			varFileMap := make(map[string]string)
			bytes, err := ioutil.ReadFile(varFile)
			if err != nil {
				log.Fatal(err)
			}
			switch filepath.Ext(varFile) {
			case ".hcl":
				err = hcl.Unmarshal(bytes, &varFileMap)
			case ".json":
				err = json.Unmarshal(bytes, &varFileMap)
			case ".yaml", ".yml":
				err = yaml.Unmarshal(bytes, &varFileMap)
			default:
				log.Fatal("unsupported varFile format")
			}
			if err != nil {
				log.Fatal(err)
			}

			for key, value := range varFileMap {
				mapvars[key] = value
			}
		}

		v.AddVariables(mapvars)

		start := time.Now()

		if !noCheckVars {
			if err := v.Parse(path, exclude); err != nil {
				log.Fatal(err)
			}
		}

		tests, err := v.Process(path, exclude)
		if err != nil {
			log.Fatal(err)
		}

		elapsed := time.Since(start)
		if err := v.OutputResult(*tests, elapsed); err != nil {
			fmt.Fprintf(os.Stderr, err.Error())
			os.Exit(1)
		}
		if strict && tests.TotalKO > 0 {
			os.Exit(2)
		}
	},
}

Cmd run

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL