Replace configuration and secret loading globals
This commit is contained in:
@@ -74,10 +74,10 @@ inputs:
|
||||
audio_s3:
|
||||
prefix: audio/
|
||||
`)
|
||||
var storeInitCalls int
|
||||
restoreAppConfigTestGlobals(t, fake, &storeInitCalls, []string{filepath.Join(t.TempDir(), "session.yml")})
|
||||
setSessionConfigSearchPaths(t, []string{filepath.Join(t.TempDir(), "session.yml")})
|
||||
deps, storeInitCalls := remoteSessionLoaderDependencies(fake)
|
||||
|
||||
loaded, err := loadCommandConfig(context.Background(), pipelinePath, "", campaignPath, "", config.SessionLoadOptions{SessionID: "2026-05-03"})
|
||||
loaded, err := loadCommandConfigWithDependencies(context.Background(), pipelinePath, "", campaignPath, "", config.SessionLoadOptions{SessionID: "2026-05-03"}, deps)
|
||||
if err != nil {
|
||||
t.Fatalf("loadCommandConfig() error = %v", err)
|
||||
}
|
||||
@@ -85,6 +85,9 @@ inputs:
|
||||
if loaded.Config.Party.Canonical == nil {
|
||||
t.Fatalf("remote config party = %#v", loaded.Config.Party)
|
||||
}
|
||||
if *storeInitCalls != 1 {
|
||||
t.Fatalf("object store init calls = %d, want 1", *storeInitCalls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoteSessionConfigIsRemovedAfterEveryCommandExit(t *testing.T) {
|
||||
@@ -153,8 +156,8 @@ inputs:
|
||||
var storeInitCalls int
|
||||
restoreAppConfigTestGlobals(t, fake, &storeInitCalls, []string{filepath.Join(t.TempDir(), "session.yml")})
|
||||
|
||||
var downloadedPath string
|
||||
captureRemoteSessionTempPath(t, &downloadedPath)
|
||||
tempRoot := t.TempDir()
|
||||
t.Setenv("TMPDIR", tempRoot)
|
||||
executor := tt.executor
|
||||
if executor == nil {
|
||||
executor = executePlan
|
||||
@@ -170,11 +173,12 @@ inputs:
|
||||
if !tt.wantSuccessful && code == 0 {
|
||||
t.Fatal("exit code = 0, want non-zero")
|
||||
}
|
||||
if downloadedPath == "" {
|
||||
t.Fatal("remote session download path was not captured")
|
||||
entries, err := os.ReadDir(tempRoot)
|
||||
if err != nil {
|
||||
t.Fatalf("read temp root: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(downloadedPath); !errors.Is(err, os.ErrNotExist) {
|
||||
t.Fatalf("downloaded remote session path still exists or could not be inspected: %q, err=%v", downloadedPath, err)
|
||||
if len(entries) != 0 {
|
||||
t.Fatalf("temporary remote session files remain after command exit: %v", entries)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -189,12 +193,12 @@ inputs:
|
||||
audio_s3:
|
||||
prefix: audio/
|
||||
`)
|
||||
var storeInitCalls int
|
||||
restoreAppConfigTestGlobals(t, fake, &storeInitCalls, []string{filepath.Join(t.TempDir(), "session.yml")})
|
||||
setSessionConfigSearchPaths(t, []string{filepath.Join(t.TempDir(), "session.yml")})
|
||||
deps, _ := remoteSessionLoaderDependencies(fake)
|
||||
|
||||
var downloadedPath string
|
||||
captureRemoteSessionTempPath(t, &downloadedPath)
|
||||
loaded, err := loadCommandConfig(context.Background(), pipelinePath, "", campaignPath, "", config.SessionLoadOptions{SessionID: "2026-05-03"})
|
||||
deps.downloadObjectToTemp = captureRemoteSessionTempPath(&downloadedPath)
|
||||
loaded, err := loadCommandConfigWithDependencies(context.Background(), pipelinePath, "", campaignPath, "", config.SessionLoadOptions{SessionID: "2026-05-03"}, deps)
|
||||
if err != nil {
|
||||
t.Fatalf("loadCommandConfig() error = %v", err)
|
||||
}
|
||||
@@ -212,17 +216,14 @@ inputs:
|
||||
}
|
||||
}
|
||||
|
||||
func captureRemoteSessionTempPath(t *testing.T, destination *string) {
|
||||
t.Helper()
|
||||
original := downloadObjectToTempFn
|
||||
downloadObjectToTempFn = func(ctx context.Context, store storage.ObjectStore, key, pattern string) (string, error) {
|
||||
path, err := original(ctx, store, key, pattern)
|
||||
func captureRemoteSessionTempPath(destination *string) func(context.Context, storage.ObjectStore, string, string) (string, error) {
|
||||
return func(ctx context.Context, store storage.ObjectStore, key, pattern string) (string, error) {
|
||||
path, err := storage.DownloadObjectToTemp(ctx, store, key, pattern)
|
||||
if err == nil {
|
||||
*destination = path
|
||||
}
|
||||
return path, err
|
||||
}
|
||||
t.Cleanup(func() { downloadObjectToTempFn = original })
|
||||
}
|
||||
|
||||
func TestExecuteRemoteSessionFallbackLoadsSecretsBeforeObjectStoreInit(t *testing.T) {
|
||||
@@ -445,6 +446,23 @@ func restoreAppConfigTestGlobals(t *testing.T, fake *storage.FakeBackend, storeI
|
||||
})
|
||||
}
|
||||
|
||||
func remoteSessionLoaderDependencies(fake *storage.FakeBackend) (commandDependencies, *int) {
|
||||
storeInitCalls := new(int)
|
||||
return commandDependencies{
|
||||
newObjectStore: func(context.Context, *config.Config) (storage.ObjectStore, error) {
|
||||
*storeInitCalls++
|
||||
return fake, nil
|
||||
},
|
||||
}, storeInitCalls
|
||||
}
|
||||
|
||||
func setSessionConfigSearchPaths(t *testing.T, paths []string) {
|
||||
t.Helper()
|
||||
original := append([]string(nil), config.DefaultSessionConfigSearchPaths...)
|
||||
config.DefaultSessionConfigSearchPaths = append([]string(nil), paths...)
|
||||
t.Cleanup(func() { config.DefaultSessionConfigSearchPaths = original })
|
||||
}
|
||||
|
||||
func seedRemoteSessionConfig(t *testing.T, fake *storage.FakeBackend, sessionID, content string) string {
|
||||
t.Helper()
|
||||
sessionPrefix := artifacts.S3SessionPrefix("dnd", "sample-campaign", sessionID)
|
||||
|
||||
Reference in New Issue
Block a user