-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathshred_test.go
84 lines (66 loc) · 1.59 KB
/
shred_test.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package shred_test
import (
"io/ioutil"
"path/filepath"
"testing"
"github.com/lu4p/shred"
)
func Example() {
shredconf := shred.Conf{Times: 1, Zeros: true, Remove: false}
shredconf.Path("/path/to/dir_or_file")
}
func ExampleConf_Path() {
shredconf := shred.Conf{Times: 1, Zeros: true, Remove: false}
shredconf.Path("/path/to/dir_or_file")
}
func ExampleConf_Dir() {
shredconf := shred.Conf{Times: 1, Zeros: true, Remove: false}
shredconf.Dir("/path/to/dir")
}
func ExampleConf_File() {
shredconf := shred.Conf{Times: 1, Zeros: true, Remove: false}
shredconf.File("/path/to/file")
}
func TestShred(t *testing.T) {
dir := t.TempDir()
filename := filepath.Join(dir, "test")
err := ioutil.WriteFile(filename, []byte("test"), 0655)
if err != nil {
t.Fatal(err)
}
shredconf := shred.Conf{Times: 1, Zeros: true, Remove: false}
if err := shredconf.File(filename); err != nil {
t.Fatal(err)
}
c, err := ioutil.ReadFile(filename)
if err != nil {
t.Fatal("File should still exist")
}
for _, b := range c {
if b != 0 {
t.Fatal("File was not overwritten with zeros")
}
}
}
func TestShredPath(t *testing.T) {
dir := t.TempDir()
filename := filepath.Join(dir, "test")
err := ioutil.WriteFile(filename, []byte("test"), 0655)
if err != nil {
t.Fatal(err)
}
shredconf := shred.Conf{Times: 1, Zeros: true, Remove: false}
t.Log(dir)
if err := shredconf.Path(dir); err != nil {
t.Fatal(err)
}
c, err := ioutil.ReadFile(filename)
if err != nil {
t.Fatal("File should still exist")
}
for _, b := range c {
if b != 0 {
t.Fatal("File was not overwritten with zeros")
}
}
}