Ejemplo n.º 1
0
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(`
Help for command foo

help for foo

--------
Gate Copyright (C) 2012-2015 Cyril Adrian <*****@*****.**>
This program comes with ABSOLUTELY NO WARRANTY; for details type show w.
This is free software, and you are welcome to redistribute it
under certain conditions; type show c for details.
`)

	err := help.Run([]string{"help", "foo"})
	if err != nil {
		t.Error(err)
	}
}
Ejemplo n.º 2
0
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)
	}
}
Ejemplo n.º 3
0
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)
	}
}
Ejemplo n.º 4
0
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)
	}
}
Ejemplo n.º 5
0
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)
	}
}
Ejemplo n.º 6
0
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)
	}
}
Ejemplo n.º 7
0
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)
	}
}
Ejemplo n.º 8
0
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)
	}
}
Ejemplo n.º 9
0
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)
	}
}
Ejemplo n.º 10
0
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)
	}
}
Ejemplo n.º 11
0
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)
	}
}
Ejemplo n.º 12
0
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)
	}
}