saasitone/pkg/msg/msg_test.go

47 lines
809 B
Go
Raw Normal View History

2021-12-21 18:42:53 -08:00
package msg
import (
"testing"
2022-11-02 16:23:26 -07:00
"github.com/mikestefanello/pagoda/pkg/tests"
2021-12-21 18:42:53 -08:00
2022-01-20 15:02:14 -08:00
"github.com/stretchr/testify/assert"
2021-12-21 18:42:53 -08:00
"github.com/stretchr/testify/require"
"github.com/labstack/echo/v4"
)
func TestMsg(t *testing.T) {
e := echo.New()
ctx, _ := tests.NewContext(e, "/")
tests.InitSession(ctx)
assertMsg := func(typ Type, message string) {
ret := Get(ctx, typ)
require.Len(t, ret, 1)
assert.Equal(t, message, ret[0])
ret = Get(ctx, typ)
require.Len(t, ret, 0)
}
2021-12-25 18:04:19 -08:00
text := "aaa"
2021-12-21 18:42:53 -08:00
Success(ctx, text)
assertMsg(TypeSuccess, text)
2021-12-25 18:04:19 -08:00
text = "bbb"
2021-12-21 18:42:53 -08:00
Info(ctx, text)
assertMsg(TypeInfo, text)
2021-12-25 18:04:19 -08:00
text = "ccc"
2021-12-21 18:42:53 -08:00
Danger(ctx, text)
assertMsg(TypeDanger, text)
2021-12-25 18:04:19 -08:00
text = "ddd"
2021-12-21 18:42:53 -08:00
Warning(ctx, text)
assertMsg(TypeWarning, text)
2021-12-25 18:04:19 -08:00
text = "eee"
2021-12-21 18:42:53 -08:00
Set(ctx, TypeSuccess, text)
assertMsg(TypeSuccess, text)
}