Added tests for funcmap.

This commit is contained in:
mikestefanello 2021-12-19 16:08:09 -05:00
parent 65a9ac9fa5
commit af645ee2e4
3 changed files with 51 additions and 5 deletions

39
funcmap/funcmap_test.go Normal file
View file

@ -0,0 +1,39 @@
package funcmap
import (
"fmt"
"testing"
"goweb/config"
"github.com/stretchr/testify/assert"
)
func TestHasField(t *testing.T) {
type example struct {
name string
}
var e example
assert.True(t, HasField(e, "name"))
assert.False(t, HasField(e, "abcd"))
}
func TestLink(t *testing.T) {
link := string(Link("/abc", "Text", "/abc"))
expected := `<a class="is-active" href="/abc">Text</a>`
assert.Equal(t, expected, link)
link = string(Link("/abc", "Text", "/abc", "first", "second"))
expected = `<a class="first second is-active" href="/abc">Text</a>`
assert.Equal(t, expected, link)
link = string(Link("/abc", "Text", "/def"))
expected = `<a class="" href="/abc">Text</a>`
assert.Equal(t, expected, link)
}
func TestGetFuncMap(t *testing.T) {
file := File("test.png")
expected := fmt.Sprintf("/%s/test.png?v=%s", config.StaticPrefix, CacheBuster)
assert.Equal(t, expected, file)
}