-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesystem_test.go
67 lines (55 loc) · 1.57 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
package main
import (
"os"
"path/filepath"
"testing"
)
func TestFilesystem_Create(t *testing.T) {
// Define test directory and file
testDir := "./testdir"
testFile := filepath.Join(testDir, "testfile.txt")
testContent := "Hello, Filesystem!"
// Test creating a directory
err := filesystem.Create(testDir, "")
if err != nil {
t.Errorf("Failed to create directory: %s", err)
}
// Test creating a file
err = filesystem.Create(testFile, testContent)
if err != nil {
t.Errorf("Failed to create file: %s", err)
}
// Check if file content is correct
content, _ := os.ReadFile(testFile)
if string(content) != testContent {
t.Errorf("File content mismatch. Got: %s, Want: %s", string(content), testContent)
}
// Cleanup
os.RemoveAll(testDir)
}
func TestFilesystem_Delete(t *testing.T) {
// Define test directory and file
testDir := "./testdir"
testFile := filepath.Join(testDir, "testfile.txt")
// Create a directory and a file to test deletion
os.MkdirAll(testDir, 0755)
os.WriteFile(testFile, []byte("test content"), 0644)
// Test deleting the file
err := filesystem.Delete(testFile)
if err != nil {
t.Errorf("Failed to delete file: %s", err)
}
// Check if file is deleted
if _, err := os.Stat(testFile); !os.IsNotExist(err) {
t.Errorf("File still exists after deletion")
}
// Test deleting the directory
err = filesystem.Delete(testDir)
if err != nil {
t.Errorf("Failed to delete directory: %s", err)
}
// Check if directory is deleted
if _, err := os.Stat(testDir); !os.IsNotExist(err) {
t.Errorf("Directory still exists after deletion")
}
}