~james/core

core/spindle/engine/archive_partial_test.go -rw-r--r-- 1.0 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 14 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package engine

import (
	"context"
	"errors"
	"io"
	"log/slog"
	"os"
	"testing"

	"tangled.org/core/spindle/artifactstore"
	"tangled.org/core/spindle/models"
)

type fakeLogStores []artifactstore.PutResult

func (f fakeLogStores) PutFile(context.Context, string, string) []artifactstore.PutResult { return f }

func TestLocalLogStaysWhenOnlyOneStoreTookTheArchive(t *testing.T) {
	d := newTestDB(t)
	t.Cleanup(func() { d.Close() })
	logDir := t.TempDir()
	wid := models.WorkflowId{PipelineId: "partial", Name: "build"}
	path := models.LogFilePath(logDir, wid)
	if err := os.WriteFile(path, []byte("log line\n"), 0o644); err != nil {
		t.Fatal(err)
	}

	l := slog.New(slog.NewTextHandler(io.Discard, nil))
	archiveLogTo(l, fakeLogStores{{}, {Err: errors.New("s3: unreachable")}}, d, logDir, wid, "did:plc:repo")

	if _, err := d.GetFinishedLog(wid); err != nil {
		t.Fatalf("no archive row although one store took the log: %v", err)
	}
	if _, err := os.Stat(path); err != nil {
		t.Fatal("the local log was removed although one of the stores failed")
	}
}