(t *testing.T)
| 78 | } |
| 79 | |
| 80 | func TestAttachmentStore_Filesystem(t *testing.T) { |
| 81 | dir := t.TempDir() |
| 82 | store := storage.NewAttachmentStore("filesystem", dir) |
| 83 | |
| 84 | t.Run("store and get", func(t *testing.T) { |
| 85 | if err := store.Store("event-1/file.txt", []byte("fs content")); err != nil { |
| 86 | t.Fatal(err) |
| 87 | } |
| 88 | |
| 89 | // Verify file exists on disk |
| 90 | data, err := os.ReadFile(filepath.Join(dir, "event-1", "file.txt")) |
| 91 | if err != nil { |
| 92 | t.Fatalf("file not on disk: %v", err) |
| 93 | } |
| 94 | if string(data) != "fs content" { |
| 95 | t.Errorf("disk content = %q, want %q", data, "fs content") |
| 96 | } |
| 97 | |
| 98 | // Get via store |
| 99 | got, err := store.Get("event-1/file.txt") |
| 100 | if err != nil { |
| 101 | t.Fatal(err) |
| 102 | } |
| 103 | if string(got) != "fs content" { |
| 104 | t.Errorf("got %q, want %q", got, "fs content") |
| 105 | } |
| 106 | }) |
| 107 | |
| 108 | t.Run("get reader filesystem", func(t *testing.T) { |
| 109 | store.Store("event-2/data.bin", []byte("fs binary")) |
| 110 | rc, err := store.GetReader("event-2/data.bin") |
| 111 | if err != nil { |
| 112 | t.Fatal(err) |
| 113 | } |
| 114 | defer rc.Close() |
| 115 | data, _ := io.ReadAll(rc) |
| 116 | if string(data) != "fs binary" { |
| 117 | t.Errorf("got %q, want %q", data, "fs binary") |
| 118 | } |
| 119 | }) |
| 120 | |
| 121 | t.Run("delete by event filesystem", func(t *testing.T) { |
| 122 | store.Store("event-5/x.txt", []byte("x")) |
| 123 | store.DeleteByEvent("event-5") |
| 124 | |
| 125 | if _, err := os.Stat(filepath.Join(dir, "event-5")); !os.IsNotExist(err) { |
| 126 | t.Error("expected event-5 directory to be removed") |
| 127 | } |
| 128 | }) |
| 129 | } |
nothing calls this directly
no test coverage detected