(t *testing.T)
| 182 | } |
| 183 | |
| 184 | func TestStateBackend_LoadFiles(t *testing.T) { |
| 185 | backend := NewStateBackend() |
| 186 | ctx := context.Background() |
| 187 | |
| 188 | // 写入一些数据 |
| 189 | if _, err := backend.Write(ctx, "/file1.txt", "content1"); err != nil { |
| 190 | t.Fatalf("Write failed: %v", err) |
| 191 | } |
| 192 | if _, err := backend.Write(ctx, "/file2.txt", "content2"); err != nil { |
| 193 | t.Fatalf("Write failed: %v", err) |
| 194 | } |
| 195 | |
| 196 | // 获取文件数据 |
| 197 | files := backend.GetFiles() |
| 198 | if len(files) != 2 { |
| 199 | t.Errorf("Expected 2 files, got %d", len(files)) |
| 200 | } |
| 201 | |
| 202 | // 创建新的 backend 并加载数据 |
| 203 | newBackend := NewStateBackend() |
| 204 | newBackend.LoadFiles(files) |
| 205 | |
| 206 | // 验证数据已恢复 |
| 207 | content, err := newBackend.Read(ctx, "/file1.txt", 0, 0) |
| 208 | if err != nil { |
| 209 | t.Fatalf("Read failed: %v", err) |
| 210 | } |
| 211 | |
| 212 | if content != "content1" { |
| 213 | t.Errorf("Expected content 'content1', got %q", content) |
| 214 | } |
| 215 | } |
nothing calls this directly
no test coverage detected