@@ -2,29 +2,13 @@ package fsutils
2
2
3
3
import (
4
4
"os"
5
+ "path/filepath"
5
6
"testing"
6
7
7
8
"github.com/stretchr/testify/assert"
8
9
"github.com/stretchr/testify/require"
9
10
)
10
11
11
- func touch (t * testing.T , name string ) {
12
- f , err := os .Create (name )
13
- if err != nil {
14
- t .Fatal (err )
15
- }
16
- if err := f .Close (); err != nil {
17
- t .Fatal (err )
18
- }
19
- }
20
-
21
- func write (t * testing.T , name , content string ) {
22
- err := os .WriteFile (name , []byte (content ), 0666 )
23
- if err != nil {
24
- t .Fatal (err )
25
- }
26
- }
27
-
28
12
func TestCopyFile (t * testing.T ) {
29
13
type args struct {
30
14
src string
@@ -72,3 +56,47 @@ func TestCopyFile(t *testing.T) {
72
56
})
73
57
}
74
58
}
59
+
60
+ func TestDirExists (t * testing.T ) {
61
+ t .Run ("invalid path" , func (t * testing.T ) {
62
+ assert .False (t , DirExists ("\000 invalid:path" ))
63
+ })
64
+
65
+ t .Run ("valid path" , func (t * testing.T ) {
66
+ assert .True (t , DirExists (t .TempDir ()))
67
+ })
68
+
69
+ t .Run ("dir not exist" , func (t * testing.T ) {
70
+ assert .False (t , DirExists (filepath .Join (t .TempDir (), "tmp" )))
71
+ })
72
+
73
+ t .Run ("file path" , func (t * testing.T ) {
74
+ filePath := filepath .Join (t .TempDir (), "tmp" )
75
+ f , err := os .Create (filePath )
76
+ require .NoError (t , f .Close ())
77
+ require .NoError (t , err )
78
+ assert .False (t , DirExists (filePath ))
79
+ })
80
+ }
81
+
82
+ func TestFileExists (t * testing.T ) {
83
+ t .Run ("invalid path" , func (t * testing.T ) {
84
+ assert .False (t , FileExists ("\000 invalid:path" ))
85
+ })
86
+
87
+ t .Run ("valid path" , func (t * testing.T ) {
88
+ filePath := filepath .Join (t .TempDir (), "tmp" )
89
+ f , err := os .Create (filePath )
90
+ require .NoError (t , f .Close ())
91
+ require .NoError (t , err )
92
+ assert .True (t , FileExists (filePath ))
93
+ })
94
+
95
+ t .Run ("file not exist" , func (t * testing.T ) {
96
+ assert .False (t , FileExists (filepath .Join (t .TempDir (), "tmp" )))
97
+ })
98
+
99
+ t .Run ("dir path" , func (t * testing.T ) {
100
+ assert .False (t , FileExists (t .TempDir ()))
101
+ })
102
+ }
0 commit comments