-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage_test.go
More file actions
48 lines (42 loc) · 1.13 KB
/
Copy pathstorage_test.go
File metadata and controls
48 lines (42 loc) · 1.13 KB
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
package contexting
import (
"path/filepath"
"testing"
"time"
)
func TestSaveAndLoadContextIndex(t *testing.T) {
tmpDir := t.TempDir()
output := filepath.Join(tmpDir, "nested", ".ctxt", "ctx_index.json")
index := &ContextIndex{
RootPath: "/tmp/project",
GeneratedAt: time.Now().UTC().Round(time.Second),
Model: defaultModel,
Tree: &Node{
FullPath: "/tmp/project",
Type: "directory",
Children: map[string]*Node{
"main.go": {
FullPath: "/tmp/project/main.go",
Type: "file",
Children: map[string]*Node{},
},
},
},
}
if err := SaveContextIndex(output, index); err != nil {
t.Fatalf("SaveContextIndex returned error: %v", err)
}
loaded, err := LoadContextIndex(output)
if err != nil {
t.Fatalf("LoadContextIndex returned error: %v", err)
}
if loaded.RootPath != index.RootPath {
t.Fatalf("expected root path %s, got %s", index.RootPath, loaded.RootPath)
}
if loaded.Model != index.Model {
t.Fatalf("expected model %s, got %s", index.Model, loaded.Model)
}
if loaded.Tree == nil || loaded.Tree.Children["main.go"] == nil {
t.Fatalf("expected tree with main.go child")
}
}