mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-08-25 09:36:24 -07:00
Use testify assertions in test functions
This commit is contained in:
parent
9ad584b035
commit
51832082a9
9 changed files with 72 additions and 50 deletions
4
go.mod
4
go.mod
|
@ -20,12 +20,16 @@ require (
|
|||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/stretchr/testify v1.8.4 // indirect
|
||||
github.com/tdewolff/parse v2.3.4+incompatible // indirect
|
||||
github.com/tdewolff/test v1.0.9 // indirect
|
||||
gitlab.com/nyarla/go-crypt v0.0.0-20160106005555-d9a5dc2b789b // indirect
|
||||
golang.org/x/image v0.7.0 // indirect
|
||||
golang.org/x/sys v0.8.0 // indirect
|
||||
golang.org/x/text v0.9.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -117,6 +117,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
|
|||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/tdewolff/minify v2.3.6+incompatible h1:2hw5/9ZvxhWLvBUnHE06gElGYz+Jv9R4Eys0XUzItYo=
|
||||
github.com/tdewolff/minify v2.3.6+incompatible/go.mod h1:9Ov578KJUmAWpS6NeZwRZyT56Uf6o3Mcz9CEsg8USYs=
|
||||
github.com/tdewolff/parse v2.3.4+incompatible h1:x05/cnGwIMf4ceLuDMBOdQ1qGniMoxpP46ghf0Qzh38=
|
||||
|
@ -221,5 +223,7 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|||
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
layeh.com/gopher-luar v1.0.10 h1:55b0mpBhN9XSshEd2Nz6WsbYXctyBT35azk4POQNSXo=
|
||||
layeh.com/gopher-luar v1.0.10/go.mod h1:TPnIVCZ2RJBndm7ohXyaqfhzjlZ+OA2SZR/YwL8tECk=
|
||||
|
|
|
@ -240,6 +240,7 @@ type BoardConfig struct {
|
|||
Worksafe bool
|
||||
ThreadPage int
|
||||
Cooldowns BoardCooldowns
|
||||
RenderURLsAsLinks bool
|
||||
ThreadsPerPage int
|
||||
EnableGeoIP bool
|
||||
}
|
||||
|
|
|
@ -4,20 +4,18 @@ import (
|
|||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestBadTypes(t *testing.T) {
|
||||
var c GochanConfig
|
||||
err := json.NewDecoder(strings.NewReader(badTypeJSON)).Decode(&c)
|
||||
if err == nil {
|
||||
t.Fatal(`"successfully" parsed JSON file with incorrect value type`)
|
||||
}
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestValidJSON(t *testing.T) {
|
||||
var c GochanConfig
|
||||
err := json.NewDecoder(strings.NewReader(validCfgJSON)).Decode(&c)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
|
|
@ -60,6 +60,11 @@ var (
|
|||
Reply: 7,
|
||||
ImageReply: 7,
|
||||
},
|
||||
RenderURLsAsLinks: true,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func SetDefaults() {
|
||||
cfg = defaultGochanConfig
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package events
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPanicRecover(t *testing.T) {
|
||||
RegisterEvent([]string{"TestPanicRecoverEvt"}, func(tr string, i ...interface{}) error {
|
||||
|
@ -9,16 +13,11 @@ func TestPanicRecover(t *testing.T) {
|
|||
return nil
|
||||
})
|
||||
handled, err, recovered := TriggerEvent("TestPanicRecoverEvt") // should panic
|
||||
if !handled {
|
||||
t.Fatal("TriggerEvent for TestPanicRecoverEvt wasn't handled")
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
assert.True(t, handled, "TriggerEvent for TestPanicRecoverEvt should be handled")
|
||||
assert.Nil(t, err)
|
||||
t.Log("TestPanicRecoverEvt recovered: ", recovered)
|
||||
if !recovered {
|
||||
t.Fatal("TestPanicRecoverEvt should have caused a panic and recovered from it")
|
||||
}
|
||||
assert.True(t, recovered, "TestPanicRecoverEvt should have caused a panic and recovered from it")
|
||||
}
|
||||
|
||||
func TestEventEditValue(t *testing.T) {
|
||||
|
@ -30,9 +29,7 @@ func TestEventEditValue(t *testing.T) {
|
|||
var a int
|
||||
t.Logf("a before TestEventEditValue triggered: %d", a)
|
||||
TriggerEvent("TestEventEditValue", &a)
|
||||
if a == 0 {
|
||||
t.Fatal("TestEventEditValue event didn't properly increment the pointer to a passed to it when triggered")
|
||||
}
|
||||
assert.NotEqual(t, 0, a, "TestEventEditValue event should increment the pointer to an int passed to it when triggered")
|
||||
t.Logf("a after TestEventEditValue triggered: %d", a)
|
||||
}
|
||||
|
||||
|
@ -46,10 +43,6 @@ func TestMultipleEventTriggers(t *testing.T) {
|
|||
TriggerEvent("b")
|
||||
aTriggered := triggered["a"]
|
||||
bTriggered := triggered["b"]
|
||||
if !aTriggered {
|
||||
t.Fatal("a event not triggered")
|
||||
}
|
||||
if !bTriggered {
|
||||
t.Fatal("b event not triggered")
|
||||
}
|
||||
assert.True(t, aTriggered, "'a' event should be triggered")
|
||||
assert.True(t, bTriggered, "'b' event should be triggered")
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/gochan-org/gochan/pkg/config"
|
||||
"github.com/gochan-org/gochan/pkg/gcsql"
|
||||
"github.com/stretchr/testify/assert"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
luar "layeh.com/gopher-luar"
|
||||
)
|
||||
|
@ -36,13 +37,9 @@ func initPluginTests() {
|
|||
func TestVersionFunction(t *testing.T) {
|
||||
initPluginTests()
|
||||
err := lState.DoString(versionStr)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
assert.Nil(t, err)
|
||||
testingVersionStr := lState.Get(-1).(lua.LString)
|
||||
if testingVersionStr != "3.4.1" {
|
||||
t.Fatalf(`%q != "3.4.1"`, testingVersionStr)
|
||||
}
|
||||
assert.EqualValues(t, "3.4.1", testingVersionStr)
|
||||
}
|
||||
|
||||
func TestStructPassing(t *testing.T) {
|
||||
|
@ -55,9 +52,7 @@ func TestStructPassing(t *testing.T) {
|
|||
}
|
||||
lState.SetGlobal("post", luar.New(lState, p))
|
||||
err := lState.DoString(structPassingStr)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
assert.Nil(t, err)
|
||||
t.Logf("Modified message text after Lua: %q", p.MessageRaw)
|
||||
if p.MessageRaw != "Message modified by a plugin\n" || p.Message != "Message modified by a plugin<br />" {
|
||||
t.Fatal("message was not properly modified by plugin")
|
||||
|
@ -67,7 +62,5 @@ func TestStructPassing(t *testing.T) {
|
|||
func TestEventPlugins(t *testing.T) {
|
||||
initPluginTests()
|
||||
err := lState.DoString(eventsTestingStr)
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
|
|
@ -1,26 +1,21 @@
|
|||
package gcutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDurationParse(t *testing.T) {
|
||||
duration, err := ParseDurationString("7y6mo5w4d3h2m1s")
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
fmt.Println(duration)
|
||||
assert.Nil(t, err)
|
||||
t.Log(duration)
|
||||
|
||||
duration, err = ParseDurationString("7year6month5weeks4days3hours2minutes1second")
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
fmt.Println(duration)
|
||||
assert.Nil(t, err)
|
||||
t.Log(duration)
|
||||
|
||||
duration, err = ParseDurationString("7 years 6 months 5 weeks 4 days 3 hours 2 minutes 1 seconds")
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
fmt.Println(duration)
|
||||
assert.Nil(t, err)
|
||||
t.Log(duration)
|
||||
}
|
||||
|
|
29
pkg/posting/formatting_test.go
Normal file
29
pkg/posting/formatting_test.go
Normal file
|
@ -0,0 +1,29 @@
|
|||
package posting
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gochan-org/gochan/pkg/config"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const (
|
||||
bbcodeMsgPreRender = `[b]Bold[/b]
|
||||
[i]Italics[/i]
|
||||
[u]Underline[/u]
|
||||
[url=https://gochan.org]URL[/url]
|
||||
[code]Code[/code]`
|
||||
bbcodeMsgPostRender = `<b>Bold</b><br><i>Italics</i><br><u>Underline</u><br><a href="https://gochan.org">URL</a><br><pre>Code</pre>`
|
||||
)
|
||||
|
||||
func TestBBCode(t *testing.T) {
|
||||
config.SetDefaults()
|
||||
var testFmtr MessageFormatter
|
||||
testFmtr.InitBBcode()
|
||||
rendered := testFmtr.Compile(bbcodeMsgPreRender, "")
|
||||
assert.Equal(t, bbcodeMsgPostRender, rendered, "Testing BBcode rendering")
|
||||
}
|
||||
|
||||
func TestLinks(t *testing.T) {
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue