debug_test.gno

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