-
Notifications
You must be signed in to change notification settings - Fork 1
/
deprecate_test.go
66 lines (46 loc) · 1.17 KB
/
deprecate_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
package export
import (
"context"
"github.com/tidwall/gjson"
"io"
"os"
"path/filepath"
"testing"
"time"
)
func TestDeprecateRecord(t *testing.T) {
ctx := context.Background()
rel_path := "fixtures/no-changes.geojson"
abs_path, err := filepath.Abs(rel_path)
if err != nil {
t.Fatalf("Failed to derive absolute path for %s, %v", rel_path, err)
}
r, err := os.Open(abs_path)
if err != nil {
t.Fatalf("Failed to open %s for reading, %v", abs_path, err)
}
defer r.Close()
body, err := io.ReadAll(r)
if err != nil {
t.Fatalf("Failed to read %s, %v", abs_path, err)
}
ex, err := NewExporter(ctx, "whosonfirst://")
if err != nil {
t.Fatalf("Failed to create exporter, %v", err)
}
now := time.Now()
new_body, err := DeprecateRecordWithTime(ctx, ex, now, body)
if err != nil {
t.Fatalf("Failed to deprecate record, %v", err)
}
expected := map[string]string{
"properties.edtf:deprecated": now.Format("2006-01-02"),
"properties.mz:is_current": "0",
}
for path, value := range expected {
rsp := gjson.GetBytes(new_body, path)
if rsp.String() != value {
t.Fatalf("Unexpected value for %s: %s (expected %s)", path, rsp.String(), value)
}
}
}