本文整理汇总了Golang中github.com/keybase/client/go/protocol.DelegateUiCtlClient类的典型用法代码示例。如果您正苦于以下问题:Golang DelegateUiCtlClient类的具体用法?Golang DelegateUiCtlClient怎么用?Golang DelegateUiCtlClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DelegateUiCtlClient类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestGregorForwardToElectron
func TestGregorForwardToElectron(t *testing.T) {
tc := setupTest(t, "gregor")
defer tc.Cleanup()
tc1 := cloneContext(tc)
svc := service.NewService(tc.G, false)
startCh := svc.GetStartChannel()
stopCh := make(chan error)
go func() {
tc.G.Log.Debug("+ Service.Run")
err := svc.Run()
tc.G.Log.Debug("- Service.Run")
if err != nil {
t.Logf("Running the service produced an error: %v", err)
}
stopCh <- err
}()
userInfo := randomUser("grgr")
sui := signupUI{
info: userInfo,
Contextified: libkb.NewContextified(tc.G),
}
tc.G.SetUI(&sui)
signup := client.NewCmdSignupRunner(tc.G)
signup.SetTest()
// Wait for the server to start up
<-startCh
if err := signup.Run(); err != nil {
t.Fatal(err)
}
tc.G.Log.Debug("Login State: %v", tc.G.LoginState())
var err error
check := func() {
if err != nil {
t.Fatal(err)
}
}
cli, xp, err := client.GetRPCClientWithContext(tc1.G)
srv := rpc.NewServer(xp, nil)
em := newElectronMock(tc.G)
err = srv.Register(keybase1.GregorUIProtocol(em))
check()
ncli := keybase1.DelegateUiCtlClient{Cli: cli}
// Spin until gregor comes up; it should come up after signup
var ok bool
for i := 0; !ok && i < 40; i++ {
if ok = svc.HasGregor(); !ok {
time.Sleep(50 * time.Millisecond)
} else {
tc.G.Log.Debug("spinning, waiting for gregor to come up (attempt %d)", i)
}
}
if !ok {
t.Fatal("Gregor never came up after we signed up")
}
svc.SetGregorPushStateFilter(func(m gregor.Message) bool {
cat := m.ToInBandMessage().ToStateUpdateMessage().Creation().Category()
return cat.String() != "user.identity_change" && cat.String() != "user.key_change"
})
err = ncli.RegisterGregorFirehose(context.TODO())
check()
select {
case a := <-em.stateCh:
if a.Reason != keybase1.PushReason_RECONNECTED {
t.Fatal(fmt.Sprintf("got wrong reason: %v", a.Reason))
}
if d := len(filterPubsubdItems(a.State.Items_)); d != 0 {
t.Fatal(fmt.Sprintf("Wrong number of items in state -- should have 0, but got %d", d))
}
case <-time.After(3 * time.Second):
t.Fatalf("never got a reconnect message")
}
msgID, err := svc.GregorInject("foo", []byte("bar"))
check()
err = svc.GregorInjectOutOfBandMessage("baz", []byte("bip"))
check()
checkState := func(s gregor1.State) {
items := filterPubsubdItems(s.Items_)
if n := len(items); n != 1 {
t.Errorf("Expected one item back; got %d", n)
return
}
i := items[0]
if !bytes.Equal(i.Md_.MsgID_.Bytes(), msgID.Bytes()) {
t.Error("Wrong gregor message ID received")
}
if i.Item_.Category_.String() != "foo" {
t.Error("Wrong gregor category")
}
if string(i.Item_.Body_.Bytes()) != "bar" {
t.Error("Wrong gregor body")
//.........这里部分代码省略.........
示例2: TestSecretUI
func TestSecretUI(t *testing.T) {
tc := setupTest(t, "secret_ui")
tc1 := cloneContext(tc)
tc2 := cloneContext(tc)
// Make sure we're not using G anywhere in our tests.
libkb.G.LocalDb = nil
defer tc.Cleanup()
stopCh := make(chan error)
svc := service.NewService(tc.G, false)
startCh := svc.GetStartChannel()
go func() {
err := svc.Run()
if err != nil {
t.Logf("Running the service produced an error: %v", err)
}
stopCh <- err
}()
// Wait for the server to start up
<-startCh
var err error
check := func() {
if err != nil {
t.Fatal(err)
}
}
sui := newSecretUI()
cli, xp, err := client.GetRPCClientWithContext(tc2.G)
check()
srv := rpc.NewServer(xp, nil)
err = srv.Register(keybase1.SecretUiProtocol(sui))
check()
ncli := keybase1.DelegateUiCtlClient{Cli: cli}
err = ncli.RegisterSecretUI(context.TODO())
check()
// run login command
loginCmdUI := &loginCmdUI{
Contextified: libkb.NewContextified(tc2.G),
}
tc2.G.SetUI(loginCmdUI)
cmd := client.NewCmdLoginRunner(tc2.G)
err = cmd.Run()
if err == nil {
t.Fatal("login worked, when it should have failed")
}
// check that delegate ui was called:
if !sui.getKeybasePassphrase {
t.Logf("secret ui: %+v", sui)
t.Error("delegate secret UI GetKeybasePassphrase was not called during login cmd")
}
stopper := client.NewCmdCtlStopRunner(tc1.G)
if err := stopper.Run(); err != nil {
t.Errorf("Error in stopping service: %v", err)
}
// If the server failed, it's also an error
err = <-stopCh
check()
}
示例3: TestDelegateUI
func TestDelegateUI(t *testing.T) {
tc := setupTest(t, "delegate_ui")
tc1 := cloneContext(tc)
tc2 := cloneContext(tc)
// Make sure we're not using G anywhere in our tests.
libkb.G.LocalDb = nil
defer tc.Cleanup()
stopCh := make(chan error)
svc := service.NewService(tc.G, false)
startCh := svc.GetStartChannel()
go func() {
err := svc.Run()
if err != nil {
t.Logf("Running the service produced an error: %v", err)
}
stopCh <- err
}()
// Wait for the server to start up
<-startCh
dui := newDelegateUI()
launchDelegateUI := func(dui *delegateUI) error {
cli, xp, err := client.GetRPCClientWithContext(tc2.G)
if err != nil {
return err
}
srv := rpc.NewServer(xp, nil)
if err = srv.Register(keybase1.IdentifyUiProtocol(dui)); err != nil {
return err
}
ncli := keybase1.DelegateUiCtlClient{Cli: cli}
if err = ncli.RegisterIdentifyUI(context.TODO()); err != nil {
return err
}
return nil
}
// Launch the delegate UI
if err := launchDelegateUI(dui); err != nil {
t.Fatal(err)
}
id := client.NewCmdIDRunner(tc1.G)
id.SetUser("t_alice")
id.UseDelegateUI()
if err := id.Run(); err != nil {
t.Errorf("Error in Run: %v", err)
}
// We should get either a 'done' or an 'error' from the delegateUI.
err, ok := <-dui.ch
if err != nil {
t.Errorf("Error with delegate UI: %v", err)
} else if ok {
t.Errorf("Delegate UI didn't close the channel properly")
} else if err = dui.checkSuccess(); err != nil {
t.Error(err)
}
stopper := client.NewCmdCtlStopRunner(tc1.G)
if err := stopper.Run(); err != nil {
t.Errorf("Error in stopping service: %v", err)
}
// If the server failed, it's also an error
if err := <-stopCh; err != nil {
t.Fatal(err)
}
}