feat: add initial implementation of Go utilities and CI workflows

This commit is contained in:
2025-06-18 16:46:01 -04:00
commit c588ade142
12 changed files with 475 additions and 0 deletions

44
Yubikey/otp_test.go Normal file
View File

@@ -0,0 +1,44 @@
package Yubikey
import (
"testing"
"time"
)
// Test the Valid method of Response.
func TestResponse_Valid(t *testing.T) {
resp := &Response{
status: "OK",
nonce: "abc123",
presentedNonce: "abc123",
}
if !resp.Valid() {
t.Errorf("Expected Valid() to return true")
}
resp.status = "BAD"
if resp.Valid() {
t.Errorf("Expected Valid() to return false when status is not OK")
}
resp.status = "OK"
resp.nonce = "xyz"
if resp.Valid() {
t.Errorf("Expected Valid() to return false when nonce does not match presentedNonce")
}
}
// Test the Time and TimeStamp methods.
func TestResponse_TimeAndTimeStamp(t *testing.T) {
now := time.Now()
resp := &Response{
t: now,
timestamp: 12345,
}
if !resp.Time().Equal(now) {
t.Errorf("Expected Time() to return the correct time")
}
if resp.TimeStamp() != 12345 {
t.Errorf("Expected TimeStamp() to return 12345")
}
}