fleet/orbit/pkg/update/runner_test.go
Lucas Manuel Rodriguez 4cfeaa1580
Do not use golangci action for better reproducibility (use make lint-go) (#6175)
* Do not use golangci action for better reproducibility

* Add fix to trigger build

* Fix all reported issues

* fix more lint errors

* Add missing import

* Remove unused method

* Remove change not necessary
2022-06-10 18:52:24 -03:00

53 lines
1.4 KiB
Go

package update
import (
"testing"
"time"
"github.com/fleetdm/fleet/v4/pkg/nettest"
"github.com/stretchr/testify/require"
)
func TestNewRunner(t *testing.T) {
// TODO(lucas): Do not use our TUF remote repository
// but instead create local repository and serve with a httptest server.
// For that, we need to move and export some functionality currently in
// "ee/fleetctl/updates.go" (as it doesn't make sense to have such functionality
// there and import such eefleetctl package here).
nettest.Run(t)
rootDir := t.TempDir()
updateOpts := DefaultOptions
updateOpts.RootDirectory = rootDir
u, err := NewUpdater(updateOpts)
require.NoError(t, err)
err = u.UpdateMetadata()
require.NoError(t, err)
runnerOpts := RunnerOptions{
CheckInterval: 1 * time.Second,
Targets: []string{"osqueryd"},
}
// NewRunner should not fail if targets do not exist locally.
r, err := NewRunner(u, runnerOpts)
require.NoError(t, err)
execPath, err := u.ExecutableLocalPath("osqueryd")
require.NoError(t, err)
require.NoFileExists(t, execPath)
// r.UpdateAction should download osqueryd.
didUpdate, err := r.UpdateAction()
require.NoError(t, err)
require.True(t, didUpdate)
require.FileExists(t, execPath)
// Create another Runner but with the target already existing.
r2, err := NewRunner(u, runnerOpts)
require.NoError(t, err)
didUpdate, err = r2.UpdateAction()
require.NoError(t, err)
require.False(t, didUpdate)
}