launchpad.net/~rogpeppe/juju-core/500-errgo-fix@v0.0.0-20140213181702-000000002356/testing/testbase/cmd_test.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testbase_test 5 6 import ( 7 "os/exec" 8 9 gc "launchpad.net/gocheck" 10 11 "launchpad.net/juju-core/testing/testbase" 12 ) 13 14 type CmdSuite struct { 15 testbase.LoggingSuite 16 } 17 18 var _ = gc.Suite(&CmdSuite{}) 19 20 func (s *CmdSuite) TestHookCommandOutput(c *gc.C) { 21 var CommandOutput = (*exec.Cmd).CombinedOutput 22 23 cmdChan, cleanup := testbase.HookCommandOutput(&CommandOutput, []byte{1, 2, 3, 4}, nil) 24 defer cleanup() 25 26 testCmd := exec.Command("fake-command", "arg1", "arg2") 27 out, err := CommandOutput(testCmd) 28 c.Assert(err, gc.IsNil) 29 cmd := <-cmdChan 30 c.Assert(out, gc.DeepEquals, []byte{1, 2, 3, 4}) 31 c.Assert(cmd.Args, gc.DeepEquals, []string{"fake-command", "arg1", "arg2"}) 32 }