run

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "run",
	Short: "Run Tests",
	Example: `  Run all testsuites containing in files ending with *.yml or *.yaml: venom run
  Run a single testsuite: venom run mytestfile.yml
  Run a single testsuite and export the result in JSON format in test/ folder: venom run mytestfile.yml --format=json --output-dir=test
  Run a single testsuite and export the result in XML and HTML formats in test/ folder: venom run mytestfile.yml --format=xml --output-dir=test --html-report
  Run a single testsuite and specify a variable: venom run mytestfile.yml --var="foo=bar"
  Run a single testsuite and load all variables from a file: venom run mytestfile.yml --var-from-file variables.yaml
  Run all testsuites containing in files ending with *.yml or *.yaml with verbosity: VENOM_VERBOSE=2 venom run
  
  Notice that variables initialized with -var-from-file argument can be overrided with -var argument
  
  More info: https://github.com/ovh/venom`,
	Long: `run integration tests`,
	PreRun: func(cmd *cobra.Command, args []string) {
		if len(args) == 0 {
			path = append(path, ".")
		} else {
			path = args[0:]
		}

		v = venom.New()
		for name, executorFunc := range executors.Registry {
			v.RegisterExecutorBuiltin(name, executorFunc())
		}
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		initArgs(cmd)

		v.OutputDir = outputDir
		v.LibDir = libDir
		v.OutputFormat = format
		v.StopOnFailure = stopOnFailure
		v.HtmlReport = htmlReport
		v.Verbose = verbose

		if err := v.InitLogger(); err != nil {
			fmt.Fprintf(os.Stderr, "%v\n", err)
			venom.OSExit(2)
		}

		if v.Verbose == 3 {
			fCPU, err := os.Create(filepath.Join(v.OutputDir, "pprof_cpu_profile.prof"))
			if err != nil {
				fmt.Fprintf(os.Stderr, "error while create profile file %v\n", err)
				venom.OSExit(2)
			}
			fMem, err := os.Create(filepath.Join(v.OutputDir, "pprof_mem_profile.prof"))
			if err != nil {
				fmt.Fprintf(os.Stderr, "error while create profile file %v\n", err)
				venom.OSExit(2)
			}
			if fCPU != nil && fMem != nil {
				pprof.StartCPUProfile(fCPU)
				p := pprof.Lookup("heap")
				defer p.WriteTo(fMem, 1)
				defer pprof.StopCPUProfile()
			}
		}
		if verbose >= 2 {
			displayArg(context.Background())
		}

		var readers = []io.Reader{}
		for _, f := range varFiles {
			if f == "" {
				continue
			}
			fi, err := os.Open(f)
			if err != nil {
				fmt.Fprintf(os.Stderr, "unable to open var-from-file %s: %v\n", f, err)
				venom.OSExit(2)
			}
			defer fi.Close()
			readers = append(readers, fi)
		}

		mapvars, err := readInitialVariables(context.Background(), variables, readers, os.Environ())
		if err != nil {
			fmt.Fprintf(os.Stderr, "%v\n", err)
			venom.OSExit(2)
		}
		v.AddVariables(mapvars)

		if err := v.Parse(context.Background(), path); err != nil {
			fmt.Fprintf(os.Stderr, "%v\n", err)
			venom.OSExit(2)
		}

		if err := v.Process(context.Background(), path); err != nil {
			fmt.Fprintf(os.Stderr, "%v\n", err)
			venom.OSExit(2)
		}

		if err := v.OutputResult(); err != nil {
			fmt.Fprintf(os.Stderr, "%v\n", err)
			venom.OSExit(2)
		}

		if v.Tests.Status == venom.StatusPass {
			fmt.Fprintf(os.Stdout, "final status: %v\n", venom.Green(v.Tests.Status))
			venom.OSExit(0)
		}
		fmt.Fprintf(os.Stdout, "final status: %v\n", venom.Red(v.Tests.Status))
		venom.OSExit(2)

		return nil
	},
}

Cmd run

Functions

This section is empty.

Types

type ConfigFileData

type ConfigFileData struct {
	Format         *string   `json:"format,omitempty" yaml:"format,omitempty"`
	LibDir         *string   `json:"lib_dir,omitempty" yaml:"lib_dir,omitempty"`
	OutputDir      *string   `json:"output_dir,omitempty" yaml:"output_dir,omitempty"`
	StopOnFailure  *bool     `json:"stop_on_failure,omitempty" yaml:"stop_on_failure,omitempty"`
	HtmlReport     *bool     `json:"html_report,omitempty" yaml:"html_report,omitempty"`
	Variables      *[]string `json:"variables,omitempty" yaml:"variables,omitempty"`
	Secrets        *[]string `json:"secrets,omitempty" yaml:"secrets,omitempty"`
	VariablesFiles *[]string `json:"variables_files,omitempty" yaml:"variables_files,omitempty"`
	Verbosity      *int      `json:"verbosity,omitempty" yaml:"verbosity,omitempty"`
}

Jump to

Keyboard shortcuts

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