diff --git a/pkg/app/entry_point.go b/pkg/app/entry_point.go index 96f6176c7..d23519a98 100644 --- a/pkg/app/entry_point.go +++ b/pkg/app/entry_point.go @@ -136,6 +136,12 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes if integrationTest != nil { integrationTest.SetupConfig(appConfig) + + // Preserve the changes that the test setup just made to the config, so + // they don't get lost when we reload the config while running the test + // (which happens when switching between repos, going in and out of + // submodules, etc). + appConfig.SaveGlobalUserConfig() } common, err := NewCommon(appConfig) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 3460c4b00..e30ff4a26 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "log" "os" "path/filepath" "strings" @@ -361,6 +362,24 @@ func loadAppState() (*AppState, error) { return appState, nil } +// SaveGlobalUserConfig saves the UserConfig back to disk. This is only used in +// integration tests, so we are a bit sloppy with error handling. +func (c *AppConfig) SaveGlobalUserConfig() { + if len(c.userConfigFiles) != 1 { + panic("expected exactly one global user config file") + } + + yamlContent, err := yaml.Marshal(c.userConfig) + if err != nil { + log.Fatalf("error marshalling user config: %v", err) + } + + err = os.WriteFile(c.userConfigFiles[0].Path, yamlContent, 0o644) + if err != nil { + log.Fatalf("error saving user config: %v", err) + } +} + // AppState stores data between runs of the app like when the last update check // was performed and which other repos have been checked out type AppState struct {