63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package store_test
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"g.fc.run/misc/byre/internal/api"
|
|
"g.fc.run/misc/byre/internal/store"
|
|
)
|
|
|
|
func TestMergingBySurvivesReopen(t *testing.T) {
|
|
ctx := context.Background()
|
|
path := filepath.Join(t.TempDir(), "byre.db")
|
|
st, err := store.Open(path, store.DefaultPortFirst, func(api.Event) {})
|
|
if err != nil {
|
|
t.Fatalf("open store: %v", err)
|
|
}
|
|
|
|
now := time.Now().UTC()
|
|
_, err = st.EnsureUser(ctx, "alice", "Alice")
|
|
if err != nil {
|
|
t.Fatalf("ensure user: %v", err)
|
|
}
|
|
err = st.CreateProject(ctx, api.Project{Id: "p1", Name: "demo", RepoPath: "/nonexistent", DefaultBranch: "main", Remote: "none", CreatedBy: "alice", CreatedAt: now})
|
|
if err != nil {
|
|
t.Fatalf("create project: %v", err)
|
|
}
|
|
err = st.CreateTask(ctx, api.Task{Id: "t1", ProjectId: "p1", Title: "t1", Branch: "t1", WorktreePath: "/nonexistent", BaseRef: "x", Status: api.TaskStatusActive, CreatedBy: "alice", CreatedAt: now}, "alice")
|
|
if err != nil {
|
|
t.Fatalf("create task: %v", err)
|
|
}
|
|
|
|
err = st.SetMergingBy(ctx, "t1", "alice")
|
|
if err != nil {
|
|
t.Fatalf("set merging by: %v", err)
|
|
}
|
|
st.Close()
|
|
|
|
st, err = store.Open(path, store.DefaultPortFirst, func(api.Event) {})
|
|
if err != nil {
|
|
t.Fatalf("reopen store: %v", err)
|
|
}
|
|
t.Cleanup(func() { st.Close() })
|
|
|
|
login, err := st.TakeMergingBy(ctx, "t1")
|
|
if err != nil {
|
|
t.Fatalf("take merging by: %v", err)
|
|
}
|
|
if login != "alice" {
|
|
t.Fatalf("merging by = %q, want alice", login)
|
|
}
|
|
|
|
login, err = st.TakeMergingBy(ctx, "t1")
|
|
if err != nil {
|
|
t.Fatalf("take merging by again: %v", err)
|
|
}
|
|
if login != "" {
|
|
t.Fatalf("merging by after take = %q, want empty", login)
|
|
}
|
|
}
|