-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstorage_test.go
More file actions
67 lines (60 loc) · 2.04 KB
/
Copy pathstorage_test.go
File metadata and controls
67 lines (60 loc) · 2.04 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
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 TestWriteBookmarksPreservesWaypointData(t *testing.T) {
path := filepath.Join(t.TempDir(), "bookmarks.gpx")
want := Waypoint{
Name: "Summit",
Lat: 12.1234567890123,
Lon: -45.9876543210987,
Ele: 1234.56789,
Time: "2026-08-26T12:34:56Z",
Desc: "High point",
}
if err := writeBookmarks(path, []Waypoint{want}); err != nil {
t.Fatalf("writeBookmarks() error = %v", err)
}
got, err := parseGPXFile(path)
if err != nil {
t.Fatalf("parseGPXFile() error = %v", err)
}
if len(got) != 1 {
t.Fatalf("parseGPXFile() returned %d waypoints, want 1", len(got))
}
if got[0].Name != want.Name || got[0].Lat != want.Lat || got[0].Lon != want.Lon ||
got[0].Ele != want.Ele || got[0].Time != want.Time || got[0].Desc != want.Desc {
t.Errorf("round trip = %+v, want %+v", got[0], want)
}
}
func TestAppendBookmarkDoesNotOverwriteMalformedFile(t *testing.T) {
path := filepath.Join(t.TempDir(), "bookmarks.gpx")
original := []byte(`<gpx><wpt lat="1" lon="2">`)
if err := os.WriteFile(path, original, 0o644); err != nil {
t.Fatalf("write malformed GPX fixture: %v", err)
}
if _, err := appendBookmark(path, Waypoint{Name: "New", Lat: 3, Lon: 4}); err == nil {
t.Fatal("appendBookmark() error = nil, want malformed GPX error")
}
got, err := os.ReadFile(path)
if err != nil {
t.Fatalf("read bookmarks after failed append: %v", err)
}
if string(got) != string(original) {
t.Errorf("bookmarks changed after failed append: got %q, want %q", got, original)
}
}
func TestCollectGPXWaypointsIgnoresImportStagingDirectories(t *testing.T) {
root := t.TempDir()
writeImportGPX(t, filepath.Join(root, "kept.gpx"), "kept", 41)
writeImportGPX(t, filepath.Join(root, "imports", ".staging-orphan", "staged.gpx"), "staged", 42)
waypoints, err := collectGPXWaypoints(root, true, "")
if err != nil {
t.Fatalf("collectGPXWaypoints() error = %v", err)
}
if len(waypoints) != 1 || waypoints[0].Name != "kept" {
t.Fatalf("collectGPXWaypoints() = %+v, want only kept waypoint", waypoints)
}
}