mirror of
https://github.com/fleetdm/fleet
synced 2026-05-17 05:58:40 +00:00
# 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. --> - [ ] 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. - [ ] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for new osquery data ingestion features. - [ ] Added/updated tests - [ ] If paths of existing endpoints are modified without backwards compatibility, checked the frontend/CLI for any necessary changes - [ ] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [ ] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [ ] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [ ] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`). - [ ] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (`runtime.GOOS`). - [ ] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. - [ ] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
package maintainedapps
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"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())
|
|
}
|
|
|
|
func TestScriptGeneration(t *testing.T) {
|
|
appsJSON, err := os.ReadFile("apps.json")
|
|
require.NoError(t, err)
|
|
|
|
var apps []maintainedApp
|
|
err = json.Unmarshal(appsJSON, &apps)
|
|
require.NoError(t, err)
|
|
|
|
for _, app := range apps {
|
|
caskJSON, err := os.ReadFile(filepath.Join("testdata", app.Identifier+".json"))
|
|
require.NoError(t, err)
|
|
|
|
var cask brewCask
|
|
err = json.Unmarshal(caskJSON, &cask)
|
|
require.NoError(t, err)
|
|
|
|
t.Run(app.Identifier, func(t *testing.T) {
|
|
installScript, err := installScriptForApp(app, &cask)
|
|
require.NoError(t, err)
|
|
assertGoldenMatches(t, app.Identifier+"_install", installScript, *update)
|
|
assertGoldenMatches(t, app.Identifier+"_uninstall", uninstallScriptForApp(&cask), *update)
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
func assertGoldenMatches(t *testing.T, goldenFile string, actual string, update bool) {
|
|
t.Helper()
|
|
goldenPath := filepath.Join("testdata", "scripts", goldenFile+".golden.sh")
|
|
|
|
var f *os.File
|
|
var err error
|
|
if update {
|
|
f, err = os.OpenFile(goldenPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
|
} else {
|
|
f, err = os.OpenFile(goldenPath, os.O_RDONLY, 0644)
|
|
}
|
|
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)
|
|
require.Equal(t, string(content), actual)
|
|
}
|