@cryptotaxi247 / kubo / commits / c6dcfaaf5

parse_test: use fileToSimulateStdin()

License: MIT Signed-off-by: Christian Couder <chriscool@tuxfamily.org>

Christian Couder committed May 3, 2015 at 10:14 UTC c6dcfaaf5d706b20b20320d0c9872a8e751c63b0
1 file changed +13 -7
commands/cli/parse_test.go
+13 -7
@@ -229,14 +229,17 @@ func TestArgumentParsing(t *testing.T) {
229 }
230
231 // Use a temp file to simulate stdin
232 - fstdin, err := ioutil.TempFile("", "")
233 - if err != nil {
234 - t.Fatal(err)
235 - }
236 - defer os.Remove(fstdin.Name())
232 + fileToSimulateStdin := func(t *testing.T, content string) (*os.File) {
233 + fstdin, err := ioutil.TempFile("", "")
234 + if err != nil {
235 + t.Fatal(err)
236 + }
237 + defer os.Remove(fstdin.Name())
238
238 - if _, err := io.WriteString(fstdin, "stdin1"); err != nil {
239 - t.Fatal(err)
239 + if _, err := io.WriteString(fstdin, content); err != nil {
240 + t.Fatal(err)
241 + }
242 + return fstdin
243 }
244
245 test := func(cmd words, f *os.File, res words) {
@@ -255,6 +258,9 @@ func TestArgumentParsing(t *testing.T) {
258 }
259
260 test([]string{"stdinenabled", "value1", "value2"}, nil, []string{"value1", "value2"})
261 +
262 + fstdin := fileToSimulateStdin(t, "stdin1")
263 +
264 test([]string{"stdinenabled"}, fstdin, []string{"stdin1"})
265 test([]string{"stdinenabled", "value1"}, fstdin, []string{"stdin1", "value1"})
266 test([]string{"stdinenabled", "value1", "value2"}, fstdin, []string{"stdin1", "value1", "value2"})