commands

package
v0.0.0-...-5f823d9 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Document = &cobra.Command{
	Use:   "document",
	Short: "Document the current image",
	Run: func(cmd *cobra.Command, args []string) {
		details := make(map[string]interface{})

		// Load reports conf file
		var testsFile testfile.TestFile
		err := fmt.Errorf("")
		if fileFlag == "" {
			testsFile, err = loadTestFile(findReportFile())
		} else {
			testsFile, err = loadTestFile(fileFlag)
		}

		if err != nil {
			fmt.Println("ERROR:", err)
			os.Exit(1)
		}

		toolchains := make(map[string]string)

		for _, suite := range suites {
			reportsToRun := testsFile.TestsToRun(suite)
			for _, report := range reportsToRun {
				if report.Type == "toolchains" {
					toolchains[report.Name] = report.Args["path"].(string)
				}
				if report.Type == "packages" {
					fmt.Println(report.Args["pkg-mgr"])
					packageDetails, err := reports.GetPackagesDetails(report.Args["pkg-mgr"].(string))
					if err != nil {
						fmt.Println("ERR: " + err.Error())
					}
					details["packages"] = packageDetails
				}
			}
		}

		toolchainDetails := reports.GetToolchainDetails(toolchains)
		if len(toolchainDetails) > 0 {
			details["toolchains"] = toolchainDetails
		}

		jsonString, _ := json.Marshal(details)
		fmt.Println(string(jsonString))
	},
}

Document will list the installed packages in the system.

View Source
var Root = &cobra.Command{
	Use:   "redalert",
	Short: "Validate system state.",
}

Root CLI command. This should have no functionality.

View Source
var Run = &cobra.Command{
	Use:   "run",
	Short: "Run tests against this system.",
	Run: func(cmd *cobra.Command, args []string) {
		var err error
		var testsFile testfile.TestFile

		if fileFlag == "" {
			testsFile, err = loadTestFile(findTestFile())
		} else {
			testsFile, err = loadTestFile(fileFlag)
		}

		if err != nil {
			fmt.Println("ERROR:", err)
			os.Exit(1)
		}

		var exitCode int

		for _, suite := range suites {
			tests := testsFile.TestsToRun(suite)
			loadedChecks, err := testfile.LoadChecks(tests)
			if err != nil {
				fmt.Println("ERROR: Unable to load checks:", err)
				continue
			}

			checksToRun := make(chan testfile.CheckToRun, len(loadedChecks))
			checkResults := make(chan checkResult, len(loadedChecks))

			n := runtime.NumCPU()
			for i := 0; i < n; i++ {
				go runCheck(checksToRun, checkResults)
			}

			for _, c := range loadedChecks {
				checksToRun <- c
			}

			timeout := time.NewTimer(5 * time.Minute)

			for i := 0; i < len(loadedChecks); i++ {
				select {
				case <-timeout.C:
					fmt.Println("ERROR: timeout expired")
					os.Exit(1)
				case r := <-checkResults:
					if r.Result == nil {
						fmt.Printf("%s: SUCCESS\n", r.Name)
					} else {
						fmt.Printf("%s: FAILURE\n%s\n", r.Name, r.Result)
						exitCode = 1
					}
				}
			}
		}

		os.Exit(exitCode)
	},
}

Run will simply run the tests. It takes zero to one arguments. If no arguments are given it looks for a tests.(yml|yaml) or redalert.(yml|yaml) in the local directory, in `$HOME/.redalert/` (`%APPDATA%\redalert` instead of `$HOME/.redalert` on windows.) and finally in `/etc/redalert/` (`C:\redalert` on windows).

It takes the following flags:

  • `--quiet` only report test failures.
  • `--jobs $VALUE` specify the number of parallel tests to run. Default to # of cores.
  • `--test $TEST_NAME` specify a test by name to run, can be provided multiple times.
  • `--suite $SUITE_NAME` which test suite to run, an [alias](#aliases) can be provided as the suite name. Can be provided multiple times. There is a default "all" alias which matches all tests and is used if `--suite` is not provided.
  • `--file $FILE_PATH` in lieu of searching in directories you can specify a file using this flag. If provided the aliases.(yml|yaml) file will not be looked for but aliases in the file will still be loaded.
  • `--output $FORMAT` specify the output format. Valid values: text, json, csv. Default: text

Run will attempt to load an additional file `aliases.(yml|yaml)` which specifies the available [aliases](#aliases). If not found aliases will be looked for as a key in the `tests.(yml|yaml)` according to the [aliases](#aliases) section.

Run will run tests in parallel.

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