Skip to content

Commit 06742db

Browse files
authored
fix(librarian): use a test-output directory for tests in update-image (#2857)
This avoids reusing existing directories under output, which will have been populated by the container prior to running tests. Fixes #2851
1 parent a8c6a7e commit 06742db

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

internal/librarian/test_container_generate.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ func (r *testGenerateRunner) run(ctx context.Context) error {
6767
// listing the failed libraries, preserving the generated files. If all tests
6868
// pass or are skipped, it cleans up the work directory.
6969
func (r *testGenerateRunner) runTests(ctx context.Context, sourceRepoHead string) error {
70-
outputDir := filepath.Join(r.workRoot, "output")
70+
outputDir := filepath.Join(r.workRoot, "test-output")
71+
if err := os.Mkdir(outputDir, 0755); err != nil {
72+
return fmt.Errorf("failed to make output directory, %s: %w", outputDir, err)
73+
}
7174
if r.library != "" {
7275
err := r.testSingleLibrary(ctx, r.library, sourceRepoHead, outputDir)
7376
if errors.Is(err, errGenerateBlocked) {

internal/librarian/update_image_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -910,15 +910,19 @@ func TestRunContainerGenerateTest(t *testing.T) {
910910
mockRepo: &MockRepository{
911911
AddAllError: fmt.Errorf("add all failed"),
912912
},
913-
testRunner: &testGenerateRunner{},
913+
testRunner: &testGenerateRunner{
914+
workRoot: t.TempDir(),
915+
},
914916
wantErrMsg: "failed to stage changes",
915917
},
916918
{
917919
name: "Commit fails with unexpected error",
918920
mockRepo: &MockRepository{
919921
CommitError: fmt.Errorf("unexpected commit error"),
920922
},
921-
testRunner: &testGenerateRunner{},
923+
testRunner: &testGenerateRunner{
924+
workRoot: t.TempDir(),
925+
},
922926
wantErrMsg: "failed to create temporary commit",
923927
},
924928
{
@@ -934,6 +938,7 @@ func TestRunContainerGenerateTest(t *testing.T) {
934938
sourceRepo: &MockRepository{},
935939
librarianConfig: &config.LibrarianConfig{},
936940
state: &config.LibrarianState{},
941+
workRoot: t.TempDir(),
937942
},
938943
wantErrMsg: "failed to reset temporary commit",
939944
wantResetCalls: 1,
@@ -949,6 +954,7 @@ func TestRunContainerGenerateTest(t *testing.T) {
949954
librarianConfig: &config.LibrarianConfig{},
950955
repo: &MockRepository{},
951956
state: &config.LibrarianState{},
957+
workRoot: t.TempDir(),
952958
},
953959
wantResetCalls: 1,
954960
},
@@ -963,6 +969,7 @@ func TestRunContainerGenerateTest(t *testing.T) {
963969
librarianConfig: &config.LibrarianConfig{},
964970
repo: &MockRepository{},
965971
state: &config.LibrarianState{},
972+
workRoot: t.TempDir(),
966973
},
967974
wantResetCalls: 0,
968975
},

0 commit comments

Comments
 (0)