-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_test.go
More file actions
55 lines (49 loc) · 1.08 KB
/
Copy pathremove_test.go
File metadata and controls
55 lines (49 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package fs_test
import (
"context"
"errors"
"fmt"
"log"
"lesiw.io/fs"
"lesiw.io/fs/osfs"
)
func ExampleRemove() {
fsys, ctx := osfs.NewTemp(), context.Background()
defer fs.Close(fsys)
err := fs.WriteFile(ctx, fsys, "delete-me.txt", []byte("temporary"))
if err != nil {
log.Fatal(err)
}
err = fs.Remove(ctx, fsys, "delete-me.txt")
if err != nil {
log.Fatal(err)
}
_, err = fs.Stat(ctx, fsys, "delete-me.txt")
if errors.Is(err, fs.ErrNotExist) {
fmt.Println("File successfully removed")
}
// Output:
// File successfully removed
}
func ExampleRemoveAll() {
fsys, ctx := osfs.NewTemp(), context.Background()
defer fs.Close(fsys)
err := fs.MkdirAll(ctx, fsys, "tree/branch/leaf")
if err != nil {
log.Fatal(err)
}
err = fs.WriteFile(ctx, fsys, "tree/file.txt", []byte("data"))
if err != nil {
log.Fatal(err)
}
err = fs.RemoveAll(ctx, fsys, "tree")
if err != nil {
log.Fatal(err)
}
_, err = fs.Stat(ctx, fsys, "tree")
if errors.Is(err, fs.ErrNotExist) {
fmt.Println("Directory tree successfully removed")
}
// Output:
// Directory tree successfully removed
}