package totp import ( "fmt" "testing" "time" "github.com/stretchr/testify/assert" ) func TestGenerateTotp(t *testing.T) { totpSecret := fmt.Sprintf("totp-secret-%d", time.Now().UnixNano()) totp, err := GenerateTotp(totpSecret) assert.NoError(t, err) assert.NotNil(t, totp) assert.NotEmpty(t, totp.Code) assert.NotEmpty(t, totp.CreatedAt) assert.NotEmpty(t, totp.ExpiresAt) assert.NotZero(t, totp.Duration) } func TestValidateTotp(t *testing.T) { totpSecret := fmt.Sprintf("totp-secret-%d", time.Now().UnixNano()) totp, err := GenerateTotp(totpSecret) assert.NoError(t, err) assert.NotNil(t, totp) assert.NoError(t, ValidateTotpToken(totp.Code, totpSecret)) }