mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
> Related issue: #19886 # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [x] Added/updated tests - [x] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [x] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. - [x] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).
76 lines
1.4 KiB
Go
76 lines
1.4 KiB
Go
//go:build !windows
|
|
// +build !windows
|
|
|
|
// based on github.com/kolide/launcher/pkg/osquery/tables
|
|
package tablehelpers
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/rs/zerolog"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestExec(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
timeout int
|
|
bins []string
|
|
args []string
|
|
err bool
|
|
output string
|
|
}{
|
|
{
|
|
name: "timeout",
|
|
timeout: 1,
|
|
bins: []string{"/bin/sleep", "/usr/bin/sleep"},
|
|
args: []string{"30"},
|
|
err: true,
|
|
},
|
|
{
|
|
name: "no binaries",
|
|
bins: []string{"/hello/world", "/hello/friends"},
|
|
err: true,
|
|
},
|
|
{
|
|
name: "false",
|
|
bins: []string{"/bin/false", "/usr/bin/false"},
|
|
err: true,
|
|
},
|
|
{
|
|
name: "eventually finds binary",
|
|
bins: []string{"/hello/world", "/bin/true", "/usr/bin/true"},
|
|
},
|
|
{
|
|
name: "output",
|
|
bins: []string{"/bin/echo"},
|
|
args: []string{"hello"},
|
|
output: "hello\n",
|
|
},
|
|
}
|
|
|
|
ctx := context.Background()
|
|
logger := zerolog.Nop()
|
|
|
|
for _, tt := range tests {
|
|
tt := tt
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if tt.timeout == 0 {
|
|
tt.timeout = 30
|
|
}
|
|
output, err := Exec(ctx, logger, tt.timeout, tt.bins, tt.args, false)
|
|
if tt.err {
|
|
assert.Error(t, err)
|
|
assert.Empty(t, output)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, []byte(tt.output), output)
|
|
}
|
|
})
|
|
}
|
|
}
|