go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/cli/shell/shell_test.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package shell_test
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"go.mondoo.com/cnquery/cli/shell"
    11  	"go.mondoo.com/cnquery/providers-sdk/v1/testutils"
    12  )
    13  
    14  func localShell() *shell.Shell {
    15  	runtime := testutils.LinuxMock()
    16  	res, err := shell.New(runtime)
    17  	if err != nil {
    18  		panic(err.Error())
    19  	}
    20  
    21  	return res
    22  }
    23  
    24  func TestShell_RunOnce(t *testing.T) {
    25  	shell := localShell()
    26  	assert.NotPanics(t, func() {
    27  		shell.RunOnce("mondoo.build")
    28  	}, "should not panic on partial queries")
    29  
    30  	assert.NotPanics(t, func() {
    31  		shell.RunOnce("mondoo { build version }")
    32  	}, "should not panic on partial queries")
    33  
    34  	assert.NotPanics(t, func() {
    35  		shell.RunOnce("mondoo { _.version }")
    36  	}, "should not panic on partial queries")
    37  }
    38  
    39  func TestShell_Help(t *testing.T) {
    40  	shell := localShell()
    41  	assert.NotPanics(t, func() {
    42  		shell.ExecCmd("help")
    43  	}, "should not panic on help command")
    44  
    45  	assert.NotPanics(t, func() {
    46  		shell.ExecCmd("help platform")
    47  	}, "should not panic on help subcommand")
    48  }
    49  
    50  func TestShell_Centos8(t *testing.T) {
    51  	shell := localShell()
    52  	assert.NotPanics(t, func() {
    53  		shell.RunOnce("platform { title name release arch }")
    54  	}, "should not panic on partial queries")
    55  }