chore(repo): reinitialize repository
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package systemfs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestListDirectoriesReturnsSortedDirectoriesAndGitFlag(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
if err := os.MkdirAll(filepath.Join(root, "b-dir"), 0o755); err != nil {
|
||||
t.Fatalf("mkdir b-dir: %v", err)
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Join(root, "a-dir", ".git"), 0o755); err != nil {
|
||||
t.Fatalf("mkdir a-dir/.git: %v", err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(root, "notes.txt"), []byte("ignored"), 0o644); err != nil {
|
||||
t.Fatalf("write notes.txt: %v", err)
|
||||
}
|
||||
|
||||
service := NewService()
|
||||
listing, err := service.ListDirectories(root)
|
||||
if err != nil {
|
||||
t.Fatalf("ListDirectories() error = %v", err)
|
||||
}
|
||||
|
||||
if listing.Current != root {
|
||||
t.Fatalf("current = %q, want %q", listing.Current, root)
|
||||
}
|
||||
if len(listing.Directories) != 2 {
|
||||
t.Fatalf("expected 2 directories, got %#v", listing.Directories)
|
||||
}
|
||||
if listing.Directories[0].Name != "a-dir" || !listing.Directories[0].IsGit {
|
||||
t.Fatalf("unexpected first directory: %#v", listing.Directories[0])
|
||||
}
|
||||
if listing.Directories[1].Name != "b-dir" || listing.Directories[1].IsGit {
|
||||
t.Fatalf("unexpected second directory: %#v", listing.Directories[1])
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateDirectoryRequiresParentAndName(t *testing.T) {
|
||||
service := NewService()
|
||||
if _, err := service.CreateDirectory("", "child"); err == nil {
|
||||
t.Fatal("expected validation error when parent is empty")
|
||||
}
|
||||
if _, err := service.CreateDirectory("/tmp", ""); err == nil {
|
||||
t.Fatal("expected validation error when name is empty")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateDirectoryCreatesPath(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
service := NewService()
|
||||
|
||||
path, err := service.CreateDirectory(root, "nested/child")
|
||||
if err != nil {
|
||||
t.Fatalf("CreateDirectory() error = %v", err)
|
||||
}
|
||||
if path != filepath.Join(root, "nested/child") {
|
||||
t.Fatalf("path = %q", path)
|
||||
}
|
||||
if info, err := os.Stat(path); err != nil || !info.IsDir() {
|
||||
t.Fatalf("expected created directory, stat err=%v info=%#v", err, info)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user