1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-07-02 03:28:25 +08:00

parse_test: use fileToSimulateStdin()

License: MIT
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
This commit is contained in:
Christian Couder
2015-05-03 10:14:56 +02:00
parent 58126c1c6c
commit c6dcfaaf5d

View File

@ -229,14 +229,17 @@ func TestArgumentParsing(t *testing.T) {
} }
// Use a temp file to simulate stdin // Use a temp file to simulate stdin
fstdin, err := ioutil.TempFile("", "") fileToSimulateStdin := func(t *testing.T, content string) (*os.File) {
if err != nil { fstdin, err := ioutil.TempFile("", "")
t.Fatal(err) if err != nil {
} t.Fatal(err)
defer os.Remove(fstdin.Name()) }
defer os.Remove(fstdin.Name())
if _, err := io.WriteString(fstdin, "stdin1"); err != nil { if _, err := io.WriteString(fstdin, content); err != nil {
t.Fatal(err) t.Fatal(err)
}
return fstdin
} }
test := func(cmd words, f *os.File, res words) { test := func(cmd words, f *os.File, res words) {
@ -255,6 +258,9 @@ func TestArgumentParsing(t *testing.T) {
} }
test([]string{"stdinenabled", "value1", "value2"}, nil, []string{"value1", "value2"}) test([]string{"stdinenabled", "value1", "value2"}, nil, []string{"value1", "value2"})
fstdin := fileToSimulateStdin(t, "stdin1")
test([]string{"stdinenabled"}, fstdin, []string{"stdin1"}) test([]string{"stdinenabled"}, fstdin, []string{"stdin1"})
test([]string{"stdinenabled", "value1"}, fstdin, []string{"stdin1", "value1"}) test([]string{"stdinenabled", "value1"}, fstdin, []string{"stdin1", "value1"})
test([]string{"stdinenabled", "value1", "value2"}, fstdin, []string{"stdin1", "value1", "value2"}) test([]string{"stdinenabled", "value1", "value2"}, fstdin, []string{"stdin1", "value1", "value2"})