1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-18 10:07:02 +00:00

chore: create Lua test helper (#532)

* Create lua test helper

Signed-off-by: James Hillyerd <james@hillyerd.com>

* Assert labels

Signed-off-by: James Hillyerd <james@hillyerd.com>

---------

Signed-off-by: James Hillyerd <james@hillyerd.com>
This commit is contained in:
James Hillyerd
2024-09-29 11:46:01 -07:00
committed by GitHub
parent b1b7e4b07c
commit 5284171dc5
6 changed files with 135 additions and 117 deletions

View File

@@ -6,9 +6,9 @@ import (
"time"
"github.com/inbucket/inbucket/v3/pkg/extension/event"
"github.com/inbucket/inbucket/v3/pkg/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
lua "github.com/yuin/gopher-lua"
)
func TestMessageMetadataGetters(t *testing.T) {
@@ -24,26 +24,22 @@ func TestMessageMetadataGetters(t *testing.T) {
script := `
assert(msg, "msg should not be nil")
function assert_eq(got, want)
assert(got == want, string.format("got name %q, wanted %q", got, want))
end
assert_eq(msg.mailbox, "mb1")
assert_eq(msg.id, "id1")
assert_eq(msg.subject, "subj1")
assert_eq(msg.size, 42)
assert_eq(msg.size, 42, "msg.size")
assert_eq(msg.from.name, "name1")
assert_eq(msg.from.address, "addr1")
assert_eq(msg.from.name, "name1", "from.name")
assert_eq(msg.from.address, "addr1", "from.address")
assert_eq(table.getn(msg.to), 1)
assert_eq(msg.to[1].name, "name2")
assert_eq(msg.to[1].address, "addr2")
assert_eq(msg.to[1].name, "name2", "to.name")
assert_eq(msg.to[1].address, "addr2", "to.address")
assert_eq(msg.date, 981173106)
assert_eq(msg.date, 981173106, "msg.date")
`
ls := lua.NewState()
ls, _ := test.NewLuaState()
registerMessageMetadataType(ls)
registerMailAddressType(ls)
ls.SetGlobal("msg", wrapMessageMetadata(ls, want))
@@ -75,7 +71,7 @@ func TestMessageMetadataSetters(t *testing.T) {
`
got := &event.MessageMetadata{}
ls := lua.NewState()
ls, _ := test.NewLuaState()
registerMessageMetadataType(ls)
registerMailAddressType(ls)
ls.SetGlobal("msg", wrapMessageMetadata(ls, got))