Skip to content

Commit b46d0be

Browse files
author
Dimitar Grigorov
committed
Add tests
1 parent 4a3b007 commit b46d0be

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

filetoolsserver/handler/copy_file_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77
"testing"
8+
"time"
89
)
910

1011
func TestHandleCopyFile_Success(t *testing.T) {
@@ -15,6 +16,10 @@ func TestHandleCopyFile_Success(t *testing.T) {
1516
dst := filepath.Join(tempDir, "dest.txt")
1617
os.WriteFile(src, []byte("content"), 0644)
1718

19+
// Set a specific mod time on source to verify preservation
20+
fixedTime := time.Date(2020, 6, 15, 12, 0, 0, 0, time.UTC)
21+
os.Chtimes(src, fixedTime, fixedTime)
22+
1823
result, _, err := h.HandleCopyFile(context.Background(), nil, CopyFileInput{Source: src, Destination: dst})
1924
if err != nil {
2025
t.Fatal(err)
@@ -23,19 +28,23 @@ func TestHandleCopyFile_Success(t *testing.T) {
2328
t.Error("expected success")
2429
}
2530

26-
// Source should still exist
2731
if _, err := os.Stat(src); err != nil {
2832
t.Error("source should still exist")
2933
}
3034

31-
// Destination should exist with same content
3235
content, err := os.ReadFile(dst)
3336
if err != nil {
3437
t.Error("destination should exist")
3538
}
3639
if string(content) != "content" {
3740
t.Errorf("wrong content: %s", content)
3841
}
42+
43+
// Verify mod time is preserved
44+
dstInfo, _ := os.Stat(dst)
45+
if !dstInfo.ModTime().Equal(fixedTime) {
46+
t.Errorf("mod time not preserved: got %v, want %v", dstInfo.ModTime(), fixedTime)
47+
}
3948
}
4049

4150
func TestHandleCopyFile_SourceNotExists(t *testing.T) {

filetoolsserver/handler/directory_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,30 @@ func TestHandleListDirectory_WithPattern(t *testing.T) {
3939
}
4040
}
4141

42+
func TestHandleListDirectory_EmptyDirectory(t *testing.T) {
43+
tempDir := t.TempDir()
44+
h := NewHandler([]string{tempDir})
45+
46+
emptyDir := filepath.Join(tempDir, "empty")
47+
os.Mkdir(emptyDir, 0755)
48+
49+
input := ListDirectoryInput{Path: emptyDir}
50+
51+
result, output, err := h.HandleListDirectory(context.Background(), nil, input)
52+
if err != nil {
53+
t.Fatal(err)
54+
}
55+
if result.IsError {
56+
t.Error("expected success")
57+
}
58+
if output.Files == nil {
59+
t.Error("expected non-nil empty slice, got nil")
60+
}
61+
if len(output.Files) != 0 {
62+
t.Errorf("expected 0 files, got %d", len(output.Files))
63+
}
64+
}
65+
4266
func TestHandleListDirectory_WithSubdirectory(t *testing.T) {
4367
tempDir := t.TempDir()
4468
h := NewHandler([]string{tempDir})

filetoolsserver/handler/edit_file_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -195,37 +195,6 @@ func TestHandleEditFile_CRLFPreservation(t *testing.T) {
195195
}
196196
}
197197

198-
func TestHandleEditFile_LFPreservation(t *testing.T) {
199-
tempDir := t.TempDir()
200-
h := NewHandler([]string{tempDir})
201-
202-
testFile := filepath.Join(tempDir, "test.txt")
203-
// Write file with LF line endings
204-
os.WriteFile(testFile, []byte("line1\nline2\nline3"), 0644)
205-
206-
input := EditFileInput{
207-
Path: testFile,
208-
Edits: []EditOperation{{OldText: "line1\nline2", NewText: "new1\nnew2"}},
209-
}
210-
211-
result, _, err := h.HandleEditFile(context.Background(), nil, input)
212-
if err != nil {
213-
t.Fatal(err)
214-
}
215-
if result.IsError {
216-
t.Errorf("expected success")
217-
}
218-
219-
// Verify LF line endings are preserved (no CRLF introduced)
220-
content, _ := os.ReadFile(testFile)
221-
if string(content) != "new1\nnew2\nline3" {
222-
t.Errorf("LF line endings should be preserved, got %q", content)
223-
}
224-
if strings.Contains(string(content), "\r\n") {
225-
t.Errorf("should not contain CRLF, got %q", content)
226-
}
227-
}
228-
229198
func TestHandleEditFile_ValidationErrors(t *testing.T) {
230199
tempDir := t.TempDir()
231200
h := NewHandler([]string{tempDir})

filetoolsserver/roots_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ func TestFileURIToPath(t *testing.T) {
103103
skip string // GOOS to skip on
104104
}{
105105
{name: "Windows drive letter", uri: "file:///C:/Users/test", want: "C:/Users/test", skip: "linux"},
106-
{name: "Windows forward slashes", uri: "file:///D:/Projects/app", want: "D:/Projects/app", skip: "linux"},
107106
{name: "Unix absolute path", uri: "file:///home/user/project", want: "/home/user/project", skip: "windows"},
108-
{name: "Unix tmp path", uri: "file:///tmp/test", want: "/tmp/test", skip: "windows"},
109107
{name: "not a file URI", uri: "/some/path", want: "/some/path"},
110108
{name: "empty string", uri: "", want: ""},
111109
}

0 commit comments

Comments
 (0)