Add basic unit tests for the gauth package.

This commit is contained in:
M. J. Fromberger
2019-03-27 11:53:52 -07:00
parent 87aa5234c1
commit bf81136148

30
gauth/gauth_test.go Normal file
View File

@ -0,0 +1,30 @@
package gauth_test
import (
"testing"
"github.com/pcarrier/gauth/gauth"
)
func TestCode(t *testing.T) {
tests := []struct {
secret string
index int64
want string
fail bool
}{
// Manually verified with the Google authenticator app.
{"ABCDEFGH", 51790421, "305441", false},
// Invalid Base32 input for the secret.
{"blargh!", 123, "", true},
}
for _, test := range tests {
got, err := gauth.Code(test.secret, test.index)
if err != nil && !test.fail {
t.Errorf("Code(%q, %d): unexpected error: %v", test.secret, test.index, err)
} else if got != test.want {
t.Errorf("Code(%q, %d): got %q, want %q", test.secret, test.index, got, test.want)
}
}
}