package globals_test import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "sneak.berlin/go/dnswatcher/internal/globals" ) // TestGlobals exercises the package-level version and appname // variables through their setters and read-back via New. These are // shared package state, so the test mutates a global and must run // sequentially; it cannot use t.Parallel(). // //nolint:paralleltest // mutates shared package-level globals, must run sequentially func TestGlobals(t *testing.T) { versions := []string{"v1.2.3", "dev", "", "v1.2.3-4-gabcdef"} for _, want := range versions { globals.SetVersion(want) g, err := globals.New(nil) require.NoError(t, err) assert.Equal(t, want, g.Version, "New must surface the version set by SetVersion") } names := []string{"dnswatcher", "other", ""} for _, want := range names { globals.SetAppname(want) g, err := globals.New(nil) require.NoError(t, err) assert.Equal(t, want, g.Appname, "New must surface the appname set by SetAppname") } // New returns a snapshot: a later SetVersion must not mutate a // Globals handed out earlier. globals.SetVersion("first") g, err := globals.New(nil) require.NoError(t, err) globals.SetVersion("second") assert.Equal(t, "first", g.Version, "a Globals returned by New must not change when the "+ "package variable is set again") }