run

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: BSD-3-Clause Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "run",
	Short: "Run Tests",
	Long: `
$ venom run *.yml

# to have more information about what's wrong on a test,
# you can use the output-dir. *.dump files will be created
# in this directory, with a lot of useful debug lines:

$ venom run *.yml --output-dir=results

Notice that variables initialized with -var-from-file argument can be overrided with -var argument.`,
	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.RegisterExecutor(redis.Name, redis.New())
		v.RegisterExecutor(kafka.Name, kafka.New())
		v.RegisterExecutor(grpc.Name, grpc.New())
		v.RegisterExecutor(rabbitmq.Name, rabbitmq.New())
		v.RegisterExecutor(sql.Name, sql.New())

		v.RegisterTestCaseContext(defaultctx.Name, defaultctx.New())
		v.RegisterTestCaseContext(webctx.Name, webctx.New())
		v.RegisterTestCaseContext(redisctx.Name, redisctx.New())
	},
	Run: func(cmd *cobra.Command, args []string) {
		v.EnableProfiling = enableProfiling
		v.LogLevel = logLevel
		v.OutputDir = outputDir
		v.OutputFormat = format
		v.Parallel = parallel
		v.StopOnFailure = stopOnFailure

		if v.EnableProfiling {
			var filename, filenameCPU, filenameMem string
			if v.OutputDir != "" {
				filename = v.OutputDir + "/"
			}
			filenameCPU = filename + "pprof_cpu_profile.prof"
			filenameMem = filename + "pprof_mem_profile.prof"
			fCPU, errCPU := os.Create(filenameCPU)
			fMem, errMem := os.Create(filenameMem)
			if errCPU != nil || errMem != nil {
				log.Errorf("error while create profile file for root process CPU:%v MEM:%v", errCPU, errMem)
			} else {
				pprof.StartCPUProfile(fCPU)
				p := pprof.Lookup("heap")
				defer p.WriteTo(fMem, 1)
				defer pprof.StopCPUProfile()
			}
		}

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

		for _, f := range varFiles {
			if f == "" {
				continue
			}
			varFileMap := make(map[string]string)
			bytes, err := ioutil.ReadFile(f)
			if err != nil {
				log.Fatal(err)
			}
			switch filepath.Ext(f) {
			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
			}
		}

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

		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