-
-
Notifications
You must be signed in to change notification settings - Fork 190
/
path_test.go
58 lines (49 loc) · 1.13 KB
/
path_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
// Copyright © Martin Tournoij – This file is part of GoatCounter and published
// under the terms of a slightly modified EUPL v1.2 license, which can be found
// in the LICENSE file or at https://license.goatcounter.com
package goatcounter_test
import (
"testing"
. "zgo.at/goatcounter/v2"
"zgo.at/goatcounter/v2/gctest"
"zgo.at/zdb"
)
func TestPathsUpdateTitle(t *testing.T) {
ctx := gctest.DB(t)
wantTitle := func(want string) {
var got string
err := zdb.Get(ctx, &got, `select title from paths limit 1`)
if err != nil {
t.Fatal(err)
}
if want != got {
t.Errorf("want: %q, got: %q", want, got)
}
}
p := Path{Path: "/x", Title: "original"}
err := p.GetOrInsert(ctx)
if err != nil {
t.Fatal(err)
}
wantTitle("original")
for i := 0; i < 10; i++ {
p2 := Path{Path: "/x", Title: "new"}
err := p2.GetOrInsert(ctx)
if err != nil {
t.Fatal(err)
}
if p2.ID != p.ID {
t.Fatalf("wrong ID: %d", p2.ID)
}
wantTitle("original")
}
p2 := Path{Path: "/x", Title: "new"}
err = p2.GetOrInsert(ctx)
if err != nil {
t.Fatal(err)
}
if p2.ID != p.ID {
t.Fatalf("wrong ID: %d", p2.ID)
}
wantTitle("new")
}