microblog_test.gno

2.05 Kb ยท 80 lines
 1package microblog
 2
 3import (
 4	"std"
 5	"strings"
 6	"testing"
 7
 8	"gno.land/p/demo/testutils"
 9	"gno.land/p/demo/urequire"
10)
11
12func TestMicroblog(t *testing.T) {
13	const (
14		author1 std.Address = testutils.TestAddress("author1")
15		author2 std.Address = testutils.TestAddress("author2")
16	)
17
18	std.TestSetOrigCaller(author1)
19
20	urequire.Equal(t, "404", Render("/wrongpath"), "rendering not giving 404")
21	urequire.NotEqual(t, "404", Render(""), "rendering / should not give 404")
22	urequire.NoError(t, m.NewPost("goodbyte, web2"), "could not create post")
23
24	_, err := m.GetPage(author1.String())
25	urequire.NoError(t, err, "silo should exist")
26
27	_, err = m.GetPage("no such author")
28	urequire.Error(t, err, "silo should not exist")
29
30	std.TestSetOrigCaller(author2)
31
32	urequire.NoError(t, m.NewPost("hello, web3"), "could not create post")
33	urequire.NoError(t, m.NewPost("hello again, web3"), "could not create post")
34	urequire.NoError(t, m.NewPost("hi again,\n web4?"), "could not create post")
35
36	println("--- MICROBLOG ---\n\n")
37
38	expected := `# gno-based microblog
39
40# pages
41
42- [g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6](/r/demo/microblog:g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6)
43- [g1v96hg6r0wge97h6lta047h6lta047h6lyz7c00](/r/demo/microblog:g1v96hg6r0wge97h6lta047h6lta047h6lyz7c00)
44`
45	urequire.Equal(t, expected, Render(""), "incorrect rendering")
46
47	expected = `## [g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6](/r/demo/microblog:g1v96hg6r0wgc47h6lta047h6lta047h6lm33tq6)
48
49joined 2009-13-02, last updated 2009-13-02
50
51## feed
52
53> goodbyte, web2
54>
55> *Fri, 13 Feb 2009 23:31:30 UTC*`
56
57	urequire.Equal(t, expected, strings.TrimSpace(Render(author1.String())), "incorrect rendering")
58
59	expected = `## [g1v96hg6r0wge97h6lta047h6lta047h6lyz7c00](/r/demo/microblog:g1v96hg6r0wge97h6lta047h6lta047h6lyz7c00)
60
61joined 2009-13-02, last updated 2009-13-02
62
63## feed
64
65> hi again,
66>
67> web4?
68>
69> *Fri, 13 Feb 2009 23:31:30 UTC*
70
71> hello again, web3
72>
73> *Fri, 13 Feb 2009 23:31:30 UTC*
74
75> hello, web3
76>
77> *Fri, 13 Feb 2009 23:31:30 UTC*`
78
79	urequire.Equal(t, expected, strings.TrimSpace(Render(author2.String())), "incorrect rendering")
80}