-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(boards2): add missing filetests for thread creation (#3644)
Add missing filetests for `CreateThread()` function. Related to #3623 This covers all tests for the function: - Successfully create a thread - Fail because board is not found - Fail because user has no permission to create a thread - Fail w/ empty title - Fail w/ empty body
- Loading branch information
1 parent
b00f9e1
commit db1dd43
Showing
8 changed files
with
163 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ func main() { | |
} | ||
|
||
// Error: | ||
// board name is empty | ||
// name is empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ func main() { | |
} | ||
|
||
// Error: | ||
// board name is empty | ||
// name is empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package main | ||
|
||
import ( | ||
"std" | ||
"strings" | ||
|
||
"gno.land/r/nt/boards2" | ||
) | ||
|
||
const ( | ||
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 | ||
title = "Test Thread" | ||
body = "Test body" | ||
path = "test-board/1" | ||
) | ||
|
||
var bid boards2.BoardID | ||
|
||
func init() { | ||
std.TestSetOrigCaller(owner) | ||
bid = boards2.CreateBoard("test-board") | ||
} | ||
|
||
func main() { | ||
pid := boards2.CreateThread(bid, title, body) | ||
|
||
// Ensure that returned ID is right | ||
println(pid == 1) | ||
|
||
// Render content must contains thread's title and body | ||
content := boards2.Render(path) | ||
println(strings.HasPrefix(content, "# "+title)) | ||
println(strings.Contains(content, body)) | ||
} | ||
|
||
// Output: | ||
// true | ||
// true | ||
// true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/r/nt/boards2" | ||
) | ||
|
||
const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 | ||
|
||
func init() { | ||
std.TestSetOrigCaller(owner) | ||
} | ||
|
||
func main() { | ||
boards2.CreateThread(404, "Foo", "bar") | ||
} | ||
|
||
// Error: | ||
// board does not exist with ID: 404 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/r/nt/boards2" | ||
) | ||
|
||
const ( | ||
owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 | ||
user = std.Address("g1us8428u2a5satrlxzagqqa5m6vmuze025anjlj") // @test2 | ||
) | ||
|
||
var bid boards2.BoardID | ||
|
||
func init() { | ||
std.TestSetOrigCaller(owner) | ||
bid = boards2.CreateBoard("test123") | ||
|
||
std.TestSetOrigCaller(user) | ||
} | ||
|
||
func main() { | ||
boards2.CreateThread(bid, "Foo", "bar") | ||
} | ||
|
||
// Error: | ||
// unauthorized |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/r/nt/boards2" | ||
) | ||
|
||
const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 | ||
|
||
var bid boards2.BoardID | ||
|
||
func init() { | ||
std.TestSetOrigCaller(owner) | ||
bid = boards2.CreateBoard("test123") | ||
} | ||
|
||
func main() { | ||
boards2.CreateThread(bid, "", "bar") | ||
} | ||
|
||
// Error: | ||
// title is empty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/r/nt/boards2" | ||
) | ||
|
||
const owner = std.Address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") // @test1 | ||
|
||
var bid boards2.BoardID | ||
|
||
func init() { | ||
std.TestSetOrigCaller(owner) | ||
bid = boards2.CreateBoard("test123") | ||
} | ||
|
||
func main() { | ||
boards2.CreateThread(bid, "Foo", "") | ||
} | ||
|
||
// Error: | ||
// body is empty |