diff --git a/gauth/gauth_test.go b/gauth/gauth_test.go new file mode 100644 index 0000000..4bed176 --- /dev/null +++ b/gauth/gauth_test.go @@ -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) + } + } +}