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 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 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) } }