From e56258267a9c7e365c585ff827c997201be3b46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Hedenstr=C3=B6m?= <erik@hedenstroem.com> Date: Sat, 18 May 2024 15:09:49 +0000 Subject: [PATCH] Added test to check that container has run --- snok_test.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/snok_test.go b/snok_test.go index dbafcbd..52cb562 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", -- GitLab