diff --git a/client/keys/export.go b/client/keys/export.go index 7e9cb88ed6..13491b5e83 100644 --- a/client/keys/export.go +++ b/client/keys/export.go @@ -31,11 +31,11 @@ FULLY AWARE OF THE RISKS. If you are unsure, you may want to do some research and export your keys in ASCII-armored encrypted format.`, Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - buf := bufio.NewReader(cmd.InOrStdin()) clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } + buf := bufio.NewReader(clientCtx.Input) unarmored, _ := cmd.Flags().GetBool(flagUnarmoredHex) unsafe, _ := cmd.Flags().GetBool(flagUnsafe) diff --git a/client/keys/export_test.go b/client/keys/export_test.go index b207a71bb1..66d990b682 100644 --- a/client/keys/export_test.go +++ b/client/keys/export_test.go @@ -1,6 +1,7 @@ package keys import ( + "bytes" "context" "fmt" "testing" @@ -25,7 +26,7 @@ func Test_runExportCmd(t *testing.T) { kbHome := t.TempDir() // create a key - kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn) + kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, nil) require.NoError(t, err) t.Cleanup(func() { kb.Delete("keyname1") // nolint:errcheck @@ -47,7 +48,8 @@ func Test_runExportCmd(t *testing.T) { clientCtx := client.Context{}. WithKeyringDir(kbHome). - WithKeyring(kb) + WithKeyring(kb). + WithInput(mockIn) ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx) require.NoError(t, cmd.ExecuteContext(ctx)) @@ -64,7 +66,9 @@ func Test_runExportCmd(t *testing.T) { cmd.SetArgs(argsUnsafeUnarmoredHex) require.Error(t, cmd.ExecuteContext(ctx)) - mockIn, mockOut := testutil.ApplyMockIO(cmd) + mockOut := bytes.NewBufferString("") + cmd.SetOut(mockOut) + cmd.SetErr(mockOut) mockIn.Reset("y\n") require.NoError(t, cmd.ExecuteContext(ctx)) require.Equal(t, "2485e33678db4175dc0ecef2d6e1fc493d4a0d7f7ce83324b6ed70afe77f3485\n", mockOut.String()) diff --git a/client/keys/import.go b/client/keys/import.go index 2b7e230654..36662a8dd2 100644 --- a/client/keys/import.go +++ b/client/keys/import.go @@ -18,11 +18,11 @@ func ImportKeyCommand() *cobra.Command { Long: "Import a ASCII armored private key into the local keybase.", Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { - buf := bufio.NewReader(cmd.InOrStdin()) clientCtx, err := client.GetClientQueryContext(cmd) if err != nil { return err } + buf := bufio.NewReader(clientCtx.Input) bz, err := ioutil.ReadFile(args[1]) if err != nil { diff --git a/client/keys/import_test.go b/client/keys/import_test.go index ea84408c2d..b12e20e9c1 100644 --- a/client/keys/import_test.go +++ b/client/keys/import_test.go @@ -1,6 +1,7 @@ package keys import ( + "bufio" "context" "fmt" "io/ioutil" @@ -23,11 +24,12 @@ func Test_runImportCmd(t *testing.T) { // Now add a temporary keybase kbHome := t.TempDir() - kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn) + kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, nil) clientCtx := client.Context{}. WithKeyringDir(kbHome). - WithKeyring(kb) + WithKeyring(kb). + WithInput(bufio.NewReader(mockIn)) ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx) require.NoError(t, err)