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