-
Notifications
You must be signed in to change notification settings - Fork 0
/
umap_test.go
80 lines (67 loc) · 1.94 KB
/
umap_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"os"
"path"
"testing"
)
func TestUmapDirectoryExists(t *testing.T) {
dir := "."
server := "http://server"
err := createUmapFiles(&dir, &server, []string{"testdata/good1.gpx"})
if err == nil {
t.Errorf("didn't fail")
}
}
func TestUmap1(t *testing.T) {
dir, _ := os.MkdirTemp("", "umap")
os.RemoveAll(dir)
defer os.RemoveAll(dir)
server := "http://server"
err := createUmapFiles(&dir, &server, []string{"testdata/flat1.jpg", "testdata/3601.jpg", "testdata/nolocation.jpg", "testdata/good1.gpx"})
if err != nil {
t.Errorf("unexpected fail %v", err)
}
// simple line counts for validations
if lineCount(path.Join(dir, "photos.csv")) != 2 {
dumpFile(path.Join(dir, "photos.csv"))
t.Errorf("photos.csv invalid line count %d", lineCount(path.Join(dir, "photos.csv")))
}
if lineCount(path.Join(dir, "photos360.csv")) != 3 {
dumpFile(path.Join(dir, "photos360.csv"))
t.Errorf("photos360.csv invalid line count %d", lineCount(path.Join(dir, "photos360.csv")))
}
if lineCount(path.Join(dir, "3601.jpg.html")) != 19 {
dumpFile(path.Join(dir, "3601.jpg.html"))
t.Errorf("3601.jpg.html invalid line count %d", lineCount(path.Join(dir, "3601.jpg.html")))
}
if lineCount(path.Join(dir, "tracks.gpx")) != 35 {
dumpFile(path.Join(dir, "tracks.gpx"))
t.Errorf("tracks.gpx invalid line count %d", lineCount(path.Join(dir, "tracks.gpx")))
}
if lineCount(path.Join(dir, "photos.umap")) != 111 {
dumpFile(path.Join(dir, "photos.umap"))
t.Errorf("photos.umap invalid line count %d", lineCount(path.Join(dir, "photos.umap")))
}
}
func dumpFile(fileName string) {
file, err := os.Open(fileName)
if err != nil {
log.Fatal(err)
}
defer file.Close()
b, _ := ioutil.ReadAll(file)
fmt.Print(string(b[:]))
}
func lineCount(fileName string) int {
file, _ := os.Open(fileName)
fileScanner := bufio.NewScanner(file)
lineCount := 0
for fileScanner.Scan() {
lineCount++
}
return lineCount
}