mirror of
https://github.com/fleetdm/fleet
synced 2026-05-14 12:38:41 +00:00
For #27267. Below is what's shown immediately after selecting an EXE: <img width="1254" alt="image" src="https://github.com/user-attachments/assets/a28d8565-de88-448a-bdbc-92aefc34ad55" /> TODO: * Tests * GitOps requirements changes * Disabling add button/adding errors when required scripts aren't specified # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/Committing-Changes.md#changes-files) for more information. - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [x] Added/updated automated tests - [x] A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it) - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Luke Heath <luke@fleetdm.com> Co-authored-by: Noah Talerman <47070608+noahtalerman@users.noreply.github.com> Co-authored-by: RachelElysia <rachel@fleetdm.com>
88 lines
2.1 KiB
Go
88 lines
2.1 KiB
Go
package file
|
|
|
|
import (
|
|
"flag"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var update = flag.Bool("update", false, "update the golden files of this test")
|
|
|
|
func TestMain(m *testing.M) {
|
|
flag.Parse()
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
// Note: to update the goldens, delete testdata/scripts/* and run the tests with `-update`:
|
|
//
|
|
// go test ./pkg/file/... -update
|
|
func TestGetInstallAndRemoveScript(t *testing.T) {
|
|
t.Parallel()
|
|
scriptsByType := map[string]map[string]string{
|
|
"msi": {
|
|
"install": "./scripts/install_msi.ps1",
|
|
"remove": "./scripts/remove_msi.ps1",
|
|
"uninstall": "./scripts/uninstall_msi.ps1",
|
|
},
|
|
"pkg": {
|
|
"install": "./scripts/install_pkg.sh",
|
|
"remove": "./scripts/remove_pkg.sh",
|
|
"uninstall": "./scripts/uninstall_pkg.sh",
|
|
},
|
|
"deb": {
|
|
"install": "./scripts/install_deb.sh",
|
|
"remove": "./scripts/remove_deb.sh",
|
|
"uninstall": "./scripts/uninstall_deb.sh",
|
|
},
|
|
"rpm": {
|
|
"install": "./scripts/install_rpm.sh",
|
|
"remove": "./scripts/remove_rpm.sh",
|
|
"uninstall": "./scripts/uninstall_rpm.sh",
|
|
},
|
|
"exe": {
|
|
"install": "",
|
|
"remove": "./scripts/remove_exe.ps1",
|
|
"uninstall": "",
|
|
},
|
|
}
|
|
|
|
for itype, scripts := range scriptsByType {
|
|
gotScript := GetInstallScript(itype)
|
|
assertGoldenMatches(t, scripts["install"], gotScript, *update)
|
|
|
|
gotScript = GetRemoveScript(itype)
|
|
assertGoldenMatches(t, scripts["remove"], gotScript, *update)
|
|
|
|
gotScript = GetUninstallScript(itype)
|
|
assertGoldenMatches(t, scripts["uninstall"], gotScript, *update)
|
|
}
|
|
}
|
|
|
|
func assertGoldenMatches(t *testing.T, goldenFile string, actual string, update bool) {
|
|
t.Helper()
|
|
if goldenFile == "" {
|
|
require.Empty(t, actual)
|
|
return
|
|
}
|
|
|
|
goldenPath := filepath.Join("testdata", goldenFile+".golden")
|
|
|
|
f, err := os.OpenFile(goldenPath, os.O_RDWR|os.O_CREATE, 0o644)
|
|
require.NoError(t, err)
|
|
defer f.Close()
|
|
|
|
if update {
|
|
_, err := f.WriteString(actual)
|
|
require.NoError(t, err)
|
|
return
|
|
}
|
|
|
|
content, err := io.ReadAll(f)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, string(content), actual)
|
|
}
|