go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/_motor/providers/os/cmd/command_test.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package cmd 5 6 import ( 7 "io/ioutil" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestCommandResource(t *testing.T) { 14 c := &CommandRunner{} 15 16 if assert.NotNil(t, c) { 17 cmd, err := c.Exec("echo", []string{"test"}) 18 assert.Equal(t, nil, err, "should execute without error") 19 assert.Equal(t, "echo test", cmd.Command, "they should be equal") 20 21 stdoutContent, _ := ioutil.ReadAll(cmd.Stdout) 22 assert.Equal(t, "test\n", string(stdoutContent), "stdout output should be correct") 23 stderrContent, _ := ioutil.ReadAll(cmd.Stderr) 24 assert.Equal(t, "", string(stderrContent), "stderr output should be correct") 25 } 26 }