~james/core

core/spindle/db/log_migration_wait_test.go -rw-r--r-- 1.1 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 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
package db

import (
	"os"
	"path/filepath"
	"testing"

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

func TestLogRenamesWaitForALogDirThatIsMissingAtBoot(t *testing.T) {
	database := newTestDB(t)
	pipelineID := models.PipelineId("3mu2xwiorc2xl")
	if _, err := database.Exec(`insert into pipeline_log_renames (knot, pipeline_id, workflow) values (?, ?, ?)`, "knot.test", pipelineID, "ci.yml"); err != nil {
		t.Fatal(err)
	}

	logDir := filepath.Join(t.TempDir(), "logs")
	if err := database.MigratePipelineLogFiles(logDir); err != nil {
		t.Fatal(err)
	}

	if err := os.MkdirAll(logDir, 0o755); err != nil {
		t.Fatal(err)
	}
	oldPath := models.LegacyLogFilePath(logDir, "knot.test", pipelineID, "ci.yml")
	if err := os.WriteFile(oldPath, []byte("old"), 0o600); err != nil {
		t.Fatal(err)
	}
	if err := database.MigratePipelineLogFiles(logDir); err != nil {
		t.Fatal(err)
	}
	newPath := models.LogFilePath(logDir, models.WorkflowId{PipelineId: pipelineID, Name: "ci.yml"})
	if data, err := os.ReadFile(newPath); err != nil || string(data) != "old" {
		t.Fatalf("log after the dir showed up = %q, %v, want it renamed", data, err)
	}
}