cmd

package
v0.0.0-...-41747ff Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "kubetest <file> [file...]",
	Short: "Run tests against a Kubernetes YAML file",
	Long:  `Run tests against a Kubernetes YAML file`,
	Run: func(cmd *cobra.Command, args []string) {
		initLogging()
		success := true
		windowsStdinIssue := false
		testsDir := viper.GetString("testsDir")
		stat, err := os.Stdin.Stat()
		if err != nil {

			if runtime.GOOS != "windows" {
				log.Error(err)
				os.Exit(1)
			} else {
				windowsStdinIssue = true
			}
		}

		if !windowsStdinIssue && ((stat.Mode() & os.ModeCharDevice) == 0) {
			var buffer bytes.Buffer
			scanner := bufio.NewScanner(os.Stdin)
			for scanner.Scan() {
				buffer.WriteString(scanner.Text() + "\n")
			}
			runSuccess := kubetest.Runs(buffer.Bytes(), testsDir, "stdin")
			if success {
				success = runSuccess
			}
		} else {
			if len(args) < 1 {
				log.Fatal("You must pass at least one file as an argument")
			}
			for _, fileName := range args {
				filePath, _ := filepath.Abs(fileName)
				fileContents, err := ioutil.ReadFile(filePath)
				if err != nil {
					log.Fatal("Could not open file ", fileName)
				}
				runSuccess := kubetest.Runs(fileContents, testsDir, fileName)
				if success {
					success = runSuccess
				}
			}
		}
		if !success {
			os.Exit(1)
		}
	},
}

RootCmd represents the the command to run when kubetest is run

Functions

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Jump to

Keyboard shortcuts

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