Added test coverage for msg package.

This commit is contained in:
mikestefanello 2021-12-21 21:42:53 -05:00
parent fc3fee1306
commit 4b91ed2f70
2 changed files with 102 additions and 36 deletions

48
msg/msg_test.go Normal file
View file

@ -0,0 +1,48 @@
package msg
import (
"testing"
"goweb/tests"
"github.com/go-playground/assert/v2"
"github.com/stretchr/testify/require"
"k8s.io/apimachinery/pkg/util/rand"
"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)
}
text := rand.String(10)
Success(ctx, text)
assertMsg(TypeSuccess, text)
text = rand.String(10)
Info(ctx, text)
assertMsg(TypeInfo, text)
text = rand.String(10)
Danger(ctx, text)
assertMsg(TypeDanger, text)
text = rand.String(10)
Warning(ctx, text)
assertMsg(TypeWarning, text)
text = rand.String(10)
Set(ctx, TypeSuccess, text)
assertMsg(TypeSuccess, text)
}