Update tests for footprint-based autostart default

Table tests for shouldEnableAutostartDefault now cover supported,
mdmDisabled, and priorInstall guards plus precedence; breadcrumb and
post-update cases are removed. Add a store test asserting ExistedAtLoad
is false with no file and true after persisting and reopening.
This commit is contained in:
mlsmaycon
2026-07-12 14:23:10 +02:00
parent 424671fb80
commit 785f76e067
2 changed files with 28 additions and 18 deletions
+11 -18
View File
@@ -12,10 +12,9 @@ import (
func TestShouldEnableAutostartDefault(t *testing.T) {
allPass := autostartDefaultState{
supported: true,
mdmDisabled: false,
postUpdateRelaunch: false,
breadcrumbPresent: true,
supported: true,
mdmDisabled: false,
priorInstall: false,
}
tests := []struct {
@@ -40,32 +39,26 @@ func TestShouldEnableAutostartDefault(t *testing.T) {
wantReason: "autostart disabled by MDM policy",
},
{
name: "post-update relaunch skips",
mutate: func(s *autostartDefaultState) { s.postUpdateRelaunch = true },
wantReason: "post-update relaunch",
},
{
name: "missing breadcrumb (upgrade or portable build) skips",
mutate: func(s *autostartDefaultState) { s.breadcrumbPresent = false },
wantReason: "no fresh-install breadcrumb",
name: "existing installation (upgrade) skips",
mutate: func(s *autostartDefaultState) { s.priorInstall = true },
wantReason: "existing NetBird installation",
},
{
name: "unsupported wins over every other guard",
mutate: func(s *autostartDefaultState) {
s.supported = false
s.mdmDisabled = true
s.postUpdateRelaunch = true
s.breadcrumbPresent = false
s.priorInstall = true
},
wantReason: "autostart not supported on this platform",
},
{
name: "breadcrumb present but relaunched after update skips",
name: "MDM disable wins over prior install",
mutate: func(s *autostartDefaultState) {
s.postUpdateRelaunch = true
s.breadcrumbPresent = true
s.mdmDisabled = true
s.priorInstall = true
},
wantReason: "post-update relaunch",
wantReason: "autostart disabled by MDM policy",
},
}
+17
View File
@@ -238,6 +238,23 @@ func TestStore_SetAutostartInitializedPersistsAcrossReload(t *testing.T) {
assert.True(t, reloaded.Get().AutostartInitialized, "marker must survive a reload from disk")
}
func TestStore_ExistedAtLoad(t *testing.T) {
withTempConfigDir(t)
// Brand-new OS user: no preferences file on disk yet.
fresh, err := NewStore(nil, nil)
require.NoError(t, err)
assert.False(t, fresh.ExistedAtLoad(), "ExistedAtLoad must be false when no file is on disk")
// Persisting a value writes the file to disk.
require.NoError(t, fresh.SetLanguage("en"))
// A subsequent GUI launch reopens the now-present file.
reopened, err := NewStore(nil, nil)
require.NoError(t, err)
assert.True(t, reopened.ExistedAtLoad(), "ExistedAtLoad must be true after the store has persisted and is reopened")
}
func TestStore_ErrUnsupportedSentinel(t *testing.T) {
// Verifies callers can match on the sentinel error rather than parsing
// strings — protects against accidental %v -> %w changes that would