debug_test.gno
1.66 Kb · 75 lines
1package debug
2
3import (
4 "std"
5 "strings"
6 "testing"
7
8 "gno.land/p/demo/uassert"
9)
10
11func TestPackage(t *testing.T) {
12 testing.SetRealm(std.NewUserRealm("g1user"))
13
14 testPackage(t)
15}
16
17func testPackage(t *testing.T) {
18 testing.SetRealm(std.NewCodeRealm("gno.land/r/test/test"))
19
20 // no debug
21 got := Render("")
22 expected := ``
23 uassert.Equal(t, expected, got)
24
25 // debug without logs
26 got = Render("?debug=1")
27 expected = `<details><summary>debug</summary>
28
29### Metadata
30| Key | Value |
31| --- | --- |
32| ±std.CurrentRealm().PkgPath()± | gno.land/r/test/test |
33| ±std.CurrentRealm().Address()± | g1z7fga7u94pdmamlvcrtvsfwxgsye0qv3rres7n |
34| ±std.PreviousRealm().PkgPath()± | |
35| ±std.PreviousRealm().Address()± | g1user |
36| ±std.ChainHeight()± | 123 |
37| ±time.Now().Format(time.RFC3339)± | 2009-02-13T23:31:30Z |
38
39</details>
40`
41 expected = strings.ReplaceAll(expected, "±", "`")
42
43 println("###################")
44 println(got)
45 println("###################")
46 println(expected)
47 println("###################")
48
49 uassert.Equal(t, expected, got)
50
51 // debug with logs
52 var d Debug
53 d.Log("hello world!")
54 d.Log("foobar")
55 got = d.Render("?debug=1")
56 expected = `<details><summary>debug</summary>
57
58### Logs
59- hello world!
60- foobar
61### Metadata
62| Key | Value |
63| --- | --- |
64| ±std.CurrentRealm().PkgPath()± | gno.land/r/test/test |
65| ±std.CurrentRealm().Address()± | g1z7fga7u94pdmamlvcrtvsfwxgsye0qv3rres7n |
66| ±std.PreviousRealm().PkgPath()± | |
67| ±std.PreviousRealm().Address()± | g1user |
68| ±std.ChainHeight()± | 123 |
69| ±time.Now().Format(time.RFC3339)± | 2009-02-13T23:31:30Z |
70
71</details>
72`
73 expected = strings.ReplaceAll(expected, "±", "`")
74 uassert.Equal(t, got, expected)
75}