Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
lgfa29 committed Sep 21, 2022
1 parent 0e1fe9e commit 42ce0a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 4 additions & 2 deletions command/operator_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/posener/complete"
)

var Stdin = os.Stdin

type OperatorAPICommand struct {
Meta

Expand Down Expand Up @@ -141,13 +143,13 @@ func (c *OperatorAPICommand) Run(args []string) int {

// Opportunistically read from stdin and POST unless method has been
// explicitly set.
stat, _ := os.Stdin.Stat()
stat, _ := Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
verbose("* Reading request body from stdin.")

// Load stdin into a *bytes.Reader so that http.NewRequest can set the
// correct Content-Length value.
b, err := ioutil.ReadAll(os.Stdin)
b, err := ioutil.ReadAll(Stdin)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error reading stdin: %v", err))
return 1
Expand Down
5 changes: 1 addition & 4 deletions command/operator_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,7 @@ func TestOperatorAPICommand_ContentLength(t *testing.T) {
_, err = tmpfile.Seek(0, 0)
require.NoError(t, err)

oldStdin := os.Stdin
defer func() { os.Stdin = oldStdin }()

os.Stdin = tmpfile
Stdin = tmpfile

// Setup command.
buf := bytes.NewBuffer(nil)
Expand Down

0 comments on commit 42ce0a2

Please sign in to comment.