justcaptcha/pkg/dwcaptcha/dwcaptcha_test.go

31 lines
663 B
Go

package dwcaptcha_test
import (
"testing"
"time"
"git.arav.su/Arav/justcaptcha/pkg/dwcaptcha"
)
const expiry = 10 * time.Minute
func TestCaptcha(t *testing.T) {
captcha := dwcaptcha.NewDwellingCaptcha(expiry)
if diff := time.Until(captcha.Expiry()) - expiry; diff >= 1*time.Microsecond {
t.Errorf("Difference %s is more than 1 microsecond", diff.String())
}
if captcha.Image("") == nil {
t.Error("image cannot be nil, but it is!")
}
if !captcha.Solve(captcha.Answer()) {
t.Error("for whatever reason, its own answer doesn't match itself O_O")
}
if !captcha.IsSolved() {
t.Error("after last test it should be true, but it is not!")
}
}