diff --git a/commands/cli/parse_test.go b/commands/cli/parse_test.go index 286a39170..92dca144b 100644 --- a/commands/cli/parse_test.go +++ b/commands/cli/parse_test.go @@ -3,6 +3,9 @@ package cli import ( "strings" "testing" + "io" + "io/ioutil" + "os" "github.com/ipfs/go-ipfs/commands" ) @@ -147,6 +150,11 @@ func TestArgumentParsing(t *testing.T) { commands.StringArg("b", true, false, "another arg"), }, }, + "stdinenabled": &commands.Command{ + Arguments: []commands.Argument{ + commands.StringArg("a", true, true, "some arg").EnableStdin(), + }, + }, }, } @@ -219,4 +227,31 @@ func TestArgumentParsing(t *testing.T) { if err == nil { t.Error("Should have failed (provided too many args, only takes 1)") } + + // Use a temp file to simulate stdin + fstdin, err := ioutil.TempFile("", "") + if err != nil { + t.Fatal(err) + } + defer os.Remove(fstdin.Name()) + + if _, err := io.WriteString(fstdin, "stdin1"); err != nil { + t.Fatal(err) + } + + _, _, _, err = Parse([]string{"stdinenabled", "value1", "value2"}, nil, rootCmd) + if err != nil { + t.Error("Should have passed") + t.Fatal(err) + } + _, _, _, err = Parse([]string{"stdinenabled"}, fstdin, rootCmd) + if err != nil { + t.Error("Should have passed") + t.Fatal(err) + } + _, _, _, err = Parse([]string{"stdinenabled", "value1"}, fstdin, rootCmd) + if err != nil { + t.Error("Should have passed") + t.Fatal(err) + } }