go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/resources/processes_test.go (about) 1 // Copyright (c) Mondoo, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package resources_test 5 6 import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "go.mondoo.com/cnquery/llx" 11 "go.mondoo.com/cnquery/types" 12 ) 13 14 func TestResource_Processes(t *testing.T) { 15 t.Run("list processes", func(t *testing.T) { 16 res := x.TestQuery(t, "processes.list") 17 assert.NotEmpty(t, res) 18 }) 19 20 t.Run("test a specific process entry", func(t *testing.T) { 21 res := x.TestQuery(t, "processes.list[0].pid") 22 assert.NotEmpty(t, res) 23 assert.Empty(t, res[0].Result().Error) 24 assert.Equal(t, int64(1), res[0].Data.Value) 25 }) 26 27 t.Run("test a specific process entry with filter v1", func(t *testing.T) { 28 res := x.TestQuery(t, "processes{ pid command }.list[0]") 29 assert.NotEmpty(t, res) 30 assert.Empty(t, res[0].Result().Error) 31 32 m, ok := res[0].Data.Value.(map[string]interface{}) 33 if !ok { 34 t.Error("failed to retrieve correct type of result") 35 t.FailNow() 36 } 37 38 assert.Equal(t, types.Block, res[0].Data.Type) 39 assert.Equal(t, llx.StringData("/sbin/init"), m["inW9aIPV3zVln3ROYYeru57EdXnE2cK452ZDPxvPs9HFaftOPsef3usY0JSS/J+EWStj+thfd7AH5XdflLF81Q=="]) 40 assert.Equal(t, llx.IntData(1), m["vGNOj/UnoXRncBiEGYvtT8Xml8xKuzl85lo7SkIdwF7X3tQLa/Tnv0M0UEA8pZdsQmfGkhHh3FFH3PiDFBEMwA=="]) 41 }) 42 }