(t *testing.T)
| 151 | } |
| 152 | |
| 153 | func TestDelete(t *testing.T) { |
| 154 | initDb(t) |
| 155 | defer cleanupDb(t) |
| 156 | |
| 157 | ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second) |
| 158 | defer cancelFn() |
| 159 | zoneId := uuid.NewString() |
| 160 | err := WFS.MakeFile(ctx, zoneId, "testfile", nil, wshrpc.FileOpts{}) |
| 161 | if err != nil { |
| 162 | t.Fatalf("error creating file: %v", err) |
| 163 | } |
| 164 | err = WFS.DeleteFile(ctx, zoneId, "testfile") |
| 165 | if err != nil { |
| 166 | t.Fatalf("error deleting file: %v", err) |
| 167 | } |
| 168 | _, err = WFS.Stat(ctx, zoneId, "testfile") |
| 169 | if err == nil || !errors.Is(err, fs.ErrNotExist) { |
| 170 | t.Errorf("expected file not found error") |
| 171 | } |
| 172 | |
| 173 | // create two files in same zone, use DeleteZone to delete |
| 174 | err = WFS.MakeFile(ctx, zoneId, "testfile1", nil, wshrpc.FileOpts{}) |
| 175 | if err != nil { |
| 176 | t.Fatalf("error creating file: %v", err) |
| 177 | } |
| 178 | err = WFS.MakeFile(ctx, zoneId, "testfile2", nil, wshrpc.FileOpts{}) |
| 179 | if err != nil { |
| 180 | t.Fatalf("error creating file: %v", err) |
| 181 | } |
| 182 | files, err := WFS.ListFiles(ctx, zoneId) |
| 183 | if err != nil { |
| 184 | t.Fatalf("error listing files: %v", err) |
| 185 | } |
| 186 | if len(files) != 2 { |
| 187 | t.Fatalf("file count mismatch") |
| 188 | } |
| 189 | if !containsFile(files, "testfile1") || !containsFile(files, "testfile2") { |
| 190 | t.Fatalf("file names mismatch") |
| 191 | } |
| 192 | err = WFS.DeleteZone(ctx, zoneId) |
| 193 | if err != nil { |
| 194 | t.Fatalf("error deleting zone: %v", err) |
| 195 | } |
| 196 | files, err = WFS.ListFiles(ctx, zoneId) |
| 197 | if err != nil { |
| 198 | t.Fatalf("error listing files: %v", err) |
| 199 | } |
| 200 | if len(files) != 0 { |
| 201 | t.Fatalf("file count mismatch") |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | func checkMapsEqual(t *testing.T, m1 map[string]any, m2 map[string]any, msg string) { |
| 206 | if len(m1) != len(m2) { |
nothing calls this directly
no test coverage detected