Add tests
gernest opened this issue · comments
@holys I am currently working on tests for the avatar package.
If anyone else is working on this maybe we should see what is the best approach. Meanwhile I try to take the path to the font file from the environment variables.
This is how my makefile looks like in the moment.
.PHONY: test
fontFile=$(CURDIR)/resource/fonts/Hiragino_Sans_GB_W3.ttf
all: install
test:
AVATAR_FONT=$(fontFile) go test -v ./avatar
install:
go install github.com/holys/initials-avatar/cmd/avatar
Note I had to rename the font file to remove spaces inorder to work in my linux machine.
And the avatar_test.go
file
package avatar
import (
"os"
"testing"
)
func TestInitialsAvatar_DrawToBytes(t *testing.T) {
fontFile := os.Getenv("AVATAR_FONT")
if fontFile == "" {
t.Skip("Font file is needed")
}
av := New(fontFile)
stuffs := []struct {
name string
size int
undersize bool
oversize bool
}{
{"Swordsmen", 22, true, false},
{"Condor Heroes", 30, false, false},
{"Condor Heroes", 30, false, false},
// {"Condor Heroes", 200, false, true},
}
for _, v := range stuffs {
_, err := av.DrawToBytes(v.name, v.size)
if err != nil {
t.Error(err)
}
}
}
Before I do something crazy, any imput will be appreciated. This is due to the fact that the local fuctions will also need tests, and will it we okay to have a test case like TestGetInitials
for testing local getInitials
function ?
Done #4