venom: github.com/ovh/venom/cli/venom/run Index | Files

package run

import "github.com/ovh/venom/cli/venom/run"

Index

Package Files

cmd.go

Variables

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.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 _, a := range variables {
            t := strings.SplitN(a, "=", 2)
            if len(t) < 2 {
                continue
            }
            mapvars[t[0]] = strings.Join(t[1:], "")
        }

        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
            }
        }

        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

Package run imports 30 packages (graph) and is imported by 3 packages. Updated 2020-07-21. Refresh now. Tools for package owners.