-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_templates_test.go
52 lines (45 loc) · 1.28 KB
/
parse_templates_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
package gowebly
import (
"os"
"path/filepath"
"testing"
)
func TestIsExistInFolder(t *testing.T) {
// Test case 1: File exists in current folder.
fileName := "testfile.txt"
filePath := filepath.Join(".", fileName)
file, err := os.Create(filePath)
if err != nil {
t.Fatalf("Failed to create test file: %v", err)
}
file.Close()
defer os.Remove(filePath)
exists := isExistInFolder(fileName, false)
if !exists {
t.Errorf("Expected file to exist, but it does not.")
}
// Test case 2: Folder exists in current folder.
folderName := "testfolder"
folderPath := filepath.Join(".", folderName)
err = os.Mkdir(folderPath, os.ModePerm)
if err != nil {
t.Fatalf("Failed to create test folder: %v", err)
}
defer os.Remove(folderPath)
exists = isExistInFolder(folderName, true)
if !exists {
t.Errorf("Expected folder to exist, but it does not.")
}
// Test case 3: File does not exist in current folder.
notExistFileName := "nonexistent.txt"
exists = isExistInFolder(notExistFileName, false)
if exists {
t.Errorf("Expected file not to exist, but it does.")
}
// Test case 4: Folder does not exist in current folder.
notExistFolderName := "nonexistent"
exists = isExistInFolder(notExistFolderName, true)
if exists {
t.Errorf("Expected folder not to exist, but it does.")
}
}