diff --git a/snok_test.go b/snok_test.go index dbafcbd0634b891ac1411486f13758ff06892e24..52cb562786e5b8a2b5fcc50d01e5844f707ce161 100644 --- a/snok_test.go +++ b/snok_test.go @@ -1,6 +1,7 @@ package snok import ( + "errors" "fmt" "io" "os" @@ -15,7 +16,7 @@ import ( var ct *CommandTest func TestMain(m *testing.M) { - rootCmd.AddCommand(echoCmd, errorCmd) + rootCmd.AddCommand(envCmd, echoCmd, errorCmd) echoCmd.Flags().BoolP("reverse", "r", false, "reverse the output") ct = NewCommandTest(rootCmd) ct.AddContainer("Test", mockContainer) @@ -55,11 +56,33 @@ var rootCmd = &cobra.Command{ }, } +var envCmd = &cobra.Command{ + Use: "env", + Args: cobra.MinimumNArgs(1), + Annotations: map[string]string{ + "order": "1", + "tests": `[ + { + "name": "Check Container Message", + "args": ["TEST_MESSAGE"], + "output": "^testing$" + } + ]`, + }, + RunE: func(cmd *cobra.Command, args []string) (err error) { + if value, ok := os.LookupEnv(args[0]); ok { + fmt.Print(value) + return + } + return errors.New(args[0] + " is undefined") + }, +} + var echoCmd = &cobra.Command{ Use: "echo", Args: cobra.MinimumNArgs(1), Annotations: map[string]string{ - "order": "1", + "order": "2", "tests": `[ { "name": "Echo", @@ -99,7 +122,7 @@ var errorCmd = &cobra.Command{ Use: "error", Args: cobra.MinimumNArgs(1), Annotations: map[string]string{ - "order": "2", + "order": "3", "tests": `[ { "name": "Expected Error",