-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesystem_test.go
92 lines (52 loc) · 1.77 KB
/
filesystem_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
85
86
87
88
89
90
91
92
/*
Copyright © 2023 Patrick Hermann [email protected]
*/
package base
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestVerifyIfFileOrDirExists(t *testing.T) {
assert := assert.New(t)
dirExists, _ := VerifyIfFileOrDirExists("/tmp", "dir")
assert.Equal(dirExists, true)
fileExists, _ := VerifyIfFileOrDirExists("/etc/os-release", "file")
assert.Equal(fileExists, true)
}
func TestVerifyFileExistence(t *testing.T) {
assert := assert.New(t)
log := StdOutFileLogger("/dev/null", "2006-01-02 15:04:05", 50, 3, 28)
fileExist := VerifyFileExistence("/tmp", log, true)
assert.Equal(fileExist, true)
}
func TestWriteDataToFile(t *testing.T) {
assert := assert.New(t)
WriteDataToFile("/tmp/output-test", "hello")
writtenText := ReadFileToVariable("/tmp/output-test")
assert.Equal(writtenText, "hello")
}
func TestReadFileToVariable(t *testing.T) {
assert := assert.New(t)
WriteDataToFile("/tmp/output-test", "hello")
writtenText := ReadFileToVariable("/tmp/output-test")
assert.Equal(writtenText, "hello")
}
func TestCreateNestedDirectoryStructure(t *testing.T) {
assert := assert.New(t)
randomFolderName := GenerateRandomString(6)
CreateNestedDirectoryStructure("/tmp/"+randomFolderName, 0600)
folderExists, _ := VerifyIfFileOrDirExists("/tmp/"+randomFolderName, "dir")
assert.Equal(true, folderExists)
}
func TestRemoveNestedFolder(t *testing.T) {
var nestedFoldersRemoved bool
assert := assert.New(t)
randomFolderName := GenerateRandomString(6)
CreateNestedDirectoryStructure("/tmp/"+randomFolderName, 0600)
folderExists, _ := VerifyIfFileOrDirExists("/tmp/"+randomFolderName, "dir")
if folderExists {
RemoveNestedFolder("/tmp/" + randomFolderName)
nestedFoldersRemoved = true
}
assert.Equal(true, nestedFoldersRemoved)
}