github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/service/crypto_test.go (about) 1 package service 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/keybase/client/go/libkb" 8 keybase1 "github.com/keybase/client/go/protocol/keybase1" 9 ) 10 11 type nullSecretUI struct{} 12 13 func (nullSecretUI) GetPassphrase(keybase1.GUIEntryArg, *keybase1.SecretEntryArg) (keybase1.GetPassphraseRes, error) { 14 return keybase1.GetPassphraseRes{}, nil 15 } 16 17 func TestCryptoSecretUI(t *testing.T) { 18 tc := libkb.SetupTest(t, "crypto", 2) 19 defer tc.Cleanup() 20 21 c := NewCryptoHandler(tc.G) 22 23 // Should return errorSecretUI because UIRouter returned an 24 // error. 25 tc.G.SetUIRouter(fakeUIRouter{secretUIErr: errors.New("fake error")}) 26 secretUI := c.getSecretUI(0, "") 27 if _, ok := secretUI.(errorSecretUI); !ok { 28 t.Errorf("secretUI %v is not an errorSecretUI", secretUI) 29 } 30 31 // Should return errorSecretUI because UIRouter returned nil. 32 tc.G.SetUIRouter(fakeUIRouter{}) 33 secretUI = c.getSecretUI(0, "") 34 if _, ok := secretUI.(errorSecretUI); !ok { 35 t.Errorf("secretUI %v is not an errorSecretUI", secretUI) 36 } 37 38 // Should return nullSecretUI.. 39 tc.G.SetUIRouter(fakeUIRouter{secretUI: nullSecretUI{}}) 40 secretUI = c.getSecretUI(0, "") 41 if _, ok := secretUI.(nullSecretUI); !ok { 42 t.Errorf("secretUI %v is not a nullSecretUI", secretUI) 43 } 44 }