func TestHelpRun2(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() cmd := NewMockCommander(ctrl) rem := remote.NewMockRemoter(ctrl) srv := server.NewMockServer(ctrl) cfg := core.NewMockConfig(ctrl) mmi := ui.NewMockUserInteraction(ctrl) help := &cmd_help{cmd, rem, srv, cfg, mmi} cmd_foo := NewMockCommand(ctrl) cmd.EXPECT().Command("foo").Return(cmd_foo) cmd_foo.EXPECT().Help([]string{"help", "foo"}).Return("\nhelp for foo\n", nil) mmi.EXPECT().Pager(` [1;32mHelp for command foo[0m help for foo [1m--------[0m [32mGate Copyright (C) 2012-2015 Cyril Adrian <*****@*****.**>[0m [32mThis program comes with ABSOLUTELY NO WARRANTY; for details type [33mshow w[32m.[0m [32mThis is free software, and you are welcome to redistribute it[0m [32munder certain conditions; type [33mshow c[32m for details.[0m `) err := help.Run([]string{"help", "foo"}) if err != nil { t.Error(err) } }
func TestAddRun3Prompt(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() cmd := NewMockCommander(ctrl) rem := remote.NewMockRemoter(ctrl) srv := server.NewMockServer(ctrl) cfg := core.NewMockConfig(ctrl) mmi := ui.NewMockUserInteraction(ctrl) add := &cmd_add{cmd, rem, srv, cfg, mmi} mmi.EXPECT().ReadPassword("Please enter the new password for foo").Return("passwd", nil) args := server.SetArgs{Key: "foo", Pass: "******"} srv.EXPECT().Set(args, gomock.Any()).Do(func(_ server.SetArgs, pass *string) { *pass = "******" }) mmi.EXPECT().Xclip("password") err := add.Run([]string{"add", "foo", "prompt"}) if err != nil { t.Error(err) } }
func TestAddRun3Generate(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() cmd := NewMockCommander(ctrl) rem := remote.NewMockRemoter(ctrl) srv := server.NewMockServer(ctrl) cfg := core.NewMockConfig(ctrl) mmi := ui.NewMockUserInteraction(ctrl) add := &cmd_add{cmd, rem, srv, cfg, mmi} cfg.EXPECT().Eval("", "console", "default_recipe", gomock.Any()).Return("recipe", nil) args := server.SetArgs{Key: "foo", Recipe: "recipe"} srv.EXPECT().Set(args, gomock.Any()).Do(func(_ server.SetArgs, pass *string) { *pass = "******" }) mmi.EXPECT().Xclip("password") err := add.Run([]string{"add", "foo", "generate"}) if err != nil { t.Error(err) } }
func TestSaveRun2(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() cmd := NewMockCommander(ctrl) rem := remote.NewMockRemoter(ctrl) srv := server.NewMockServer(ctrl) cfg := core.NewMockConfig(ctrl) mmi := ui.NewMockUserInteraction(ctrl) save := &cmd_save{cmd, rem, srv, cfg, mmi} rmt := remote.NewMockRemote(ctrl) rem.EXPECT().Remote("foo").Return(rmt, nil) path := "vault_path" cfg.EXPECT().VaultPath().Return(path, nil) srv.EXPECT().Save(true, gomock.Any()).Do(func(_ bool, reply *bool) { *reply = true }) rmt.EXPECT().SaveVault(path) err := save.Run([]string{"save", "foo"}) if err != nil { t.Error(err) } }
func TestGetRun2(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() cmd := NewMockCommander(ctrl) rem := remote.NewMockRemoter(ctrl) srv := server.NewMockServer(ctrl) cfg := core.NewMockConfig(ctrl) mmi := ui.NewMockUserInteraction(ctrl) get := &cmd_get{cmd, rem, srv, cfg, mmi} mmi.EXPECT().XclipPassword("foo") err := get.Run([]string{"get", "foo"}) if err != nil { t.Error(err) } }
func TestSetMaster3(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() cmd := NewMockCommander(ctrl) rem := remote.NewMockRemoter(ctrl) srv := server.NewMockServer(ctrl) cfg := core.NewMockConfig(ctrl) mmi := ui.NewMockUserInteraction(ctrl) merge := &cmd_master{cmd, rem, srv, cfg, mmi} mmi.EXPECT().ReadPassword(gomock.Any()).Return("", nil) err := merge.Run([]string{"master"}) if err == nil || !strings.HasPrefix(err.Error(), "Cancelled\n") { t.Error(err) } }
func TestStopRun_could_not_stop(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() cmd := NewMockCommander(ctrl) rem := remote.NewMockRemoter(ctrl) srv := server.NewMockServer(ctrl) cfg := core.NewMockConfig(ctrl) mmi := ui.NewMockUserInteraction(ctrl) stop := &cmd_stop{cmd, rem, srv, cfg, mmi} srv.EXPECT().Stop(0, gomock.Any()).Do(func(_ int, reply *bool) { *reply = false }) err := stop.Run([]string{"stop"}) if err == io.EOF || err.(errors.StackError).Nested.Error() != "The server refused to stop" { t.Error(err) } }
func TestStopRun(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() cmd := NewMockCommander(ctrl) rem := remote.NewMockRemoter(ctrl) srv := server.NewMockServer(ctrl) cfg := core.NewMockConfig(ctrl) mmi := ui.NewMockUserInteraction(ctrl) stop := &cmd_stop{cmd, rem, srv, cfg, mmi} srv.EXPECT().Stop(0, gomock.Any()).Do(func(_ int, reply *bool) { *reply = true }) err := stop.Run([]string{"stop"}) if err != io.EOF { t.Error(err) } }
func TestListRun1(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() cmd := NewMockCommander(ctrl) rem := remote.NewMockRemoter(ctrl) srv := server.NewMockServer(ctrl) cfg := core.NewMockConfig(ctrl) mmi := ui.NewMockUserInteraction(ctrl) list := &cmd_list{cmd, rem, srv, cfg, mmi} srv.EXPECT().List(".*", gomock.Any()).Do(func(filter string, reply *[]string) { *reply = []string{"key1", "key2"} }) mmi.EXPECT().Pager("key1\nkey2\n") err := list.Run([]string{"list"}) if err != nil { t.Error(err) } }
func TestMergeRun2(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() cmd := NewMockCommander(ctrl) rem := remote.NewMockRemoter(ctrl) srv := server.NewMockServer(ctrl) cfg := core.NewMockConfig(ctrl) mmi := ui.NewMockUserInteraction(ctrl) merge := &cmd_merge{cmd, rem, srv, cfg, mmi} rmt := remote.NewMockRemote(ctrl) rem.EXPECT().Remote("foo").Return(rmt, nil) xdg := core.NewMockXdgContext(ctrl) cfg.EXPECT().Xdg().Return(xdg, nil) xdg.EXPECT().RuntimeDir().Return("runtimeDir", nil) rmt.EXPECT().LoadVault("runtimeDir/merge_vault").Return(nil) pass := "******" mmi.EXPECT().ReadPassword(gomock.Any()).Return(pass, nil) srv.EXPECT().Merge(server.MergeArgs{"runtimeDir/merge_vault", pass}, gomock.Any()).Do(func(_ server.MergeArgs, reply *bool) { *reply = true }) save := NewMockCommand(ctrl) cmd.EXPECT().Command("save").Return(save) save.EXPECT().Run([]string{"merge", "foo"}) path := "vault_path" cfg.EXPECT().VaultPath().Return(path, nil) rmt.EXPECT().SaveVault(path) err := merge.Run([]string{"merge", "foo"}) if err != nil { t.Error(err) } }
func TestSetMaster1(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() cmd := NewMockCommander(ctrl) rem := remote.NewMockRemoter(ctrl) srv := server.NewMockServer(ctrl) cfg := core.NewMockConfig(ctrl) mmi := ui.NewMockUserInteraction(ctrl) merge := &cmd_master{cmd, rem, srv, cfg, mmi} pass := "******" mmi.EXPECT().ReadPassword(gomock.Any()).Return(pass, nil) mmi.EXPECT().ReadPassword(gomock.Any()).Return(pass, nil) srv.EXPECT().SetMaster(pass, gomock.Any()).Do(func(_ string, reply *bool) { *reply = true }) err := merge.Run([]string{"master"}) if err != nil { t.Error(err) } }
func TestLoadRun2(t *testing.T) { ctrl := gomock.NewController(t) defer ctrl.Finish() cmd := NewMockCommander(ctrl) rem := remote.NewMockRemoter(ctrl) srv := server.NewMockServer(ctrl) cfg := core.NewMockConfig(ctrl) mmi := ui.NewMockUserInteraction(ctrl) load := &cmd_load{cmd, rem, srv, cfg, mmi} rmt := remote.NewMockRemote(ctrl) rem.EXPECT().Remote("foo").Return(rmt, nil) path := "vault_path" cfg.EXPECT().VaultPath().Return(path, nil) rmt.EXPECT().LoadVault(path) err := load.Run([]string{"load", "foo"}) if err != nil { t.Error(err) } }