Commit d0752a71 authored by Christian Couder's avatar Christian Couder

parse_test: add tests for stdin enabled arg

Let's document how stdin enabled arguments currently
work by adding some tests.

License: MIT
Signed-off-by: default avatarChristian Couder <chriscool@tuxfamily.org>
parent 3e4a0694
......@@ -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)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment