| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestTopicStateWritesSkipDeletedWorkspaceRoot(t *testing.T) { |
| 10 | root := filepath.Join(t.TempDir(), "workspace-a") |
| 11 | if err := os.MkdirAll(root, 0o755); err != nil { |
| 12 | t.Fatal(err) |
| 13 | } |
| 14 | if err := saveTopicTitles(root, map[string]string{"topic_1": "kept"}); err != nil { |
| 15 | t.Fatalf("saveTopicTitles on a live root: %v", err) |
| 16 | } |
| 17 | |
| 18 | if err := os.RemoveAll(root); err != nil { |
| 19 | t.Fatal(err) |
| 20 | } |
| 21 | if err := saveTopicTitles(root, map[string]string{"topic_1": "resurrected"}); err == nil { |
| 22 | t.Fatal("writing topic titles into a deleted workspace must fail instead of recreating it") |
| 23 | } |
| 24 | if _, err := os.Stat(root); !os.IsNotExist(err) { |
| 25 | t.Fatalf("workspace root was recreated: %v", err) |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | func TestTopicStateWritesStillCreateGlobalDir(t *testing.T) { |
| 30 | t.Setenv("REASONIX_HOME", t.TempDir()) |
| 31 | |
| 32 | if err := saveTopicTitles("", map[string]string{"topic_1": "global"}); err != nil { |
| 33 | t.Fatalf("global topic titles must still be writable: %v", err) |
| 34 | } |
| 35 | if got := loadTopicTitles("")["topic_1"]; got != "global" { |
| 36 | t.Fatalf("global topic title = %q, want %q", got, "global") |
| 37 | } |
| 38 | } |
| 39 |