github.com/tommi2day/gomodules@v1.13.2-0.20240423190010-b7d55d252a27/pwlib/totp_test.go (about) 1 package pwlib 2 3 import ( 4 "regexp" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 const wrong = "xxx" 11 const ok = "GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ" 12 13 // TestGetOutput Test GetOutput output should return expected value 14 func TestGetOTP(t *testing.T) { 15 t.Run("invalid secret", func(t *testing.T) { 16 _, err := GetOtp(wrong) 17 assert.Errorf(t, err, "Invalid secret given, but claims ok") 18 }) 19 t.Run("valid secret", func(t *testing.T) { 20 val, err := GetOtp(ok) 21 assert.NoErrorf(t, err, "valid secret given, but claims failed") 22 assert.NotEmpty(t, val, "valid secret given, answer empty") 23 assert.Lenf(t, val, 6, "should have exact 6 char") 24 assert.Regexpf(t, regexp.MustCompile(`^\d+$`), val, "should only digits") 25 t.Logf("OTP: %s", val) 26 }) 27 }