-
Notifications
You must be signed in to change notification settings - Fork 542
/
Copy pathexec_test.go
61 lines (52 loc) · 1.44 KB
/
exec_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2012 tsuru authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package exec
import (
"bytes"
"testing"
"github.com/tsuru/commandmocker"
check "gopkg.in/check.v1"
)
type S struct{}
var _ = check.Suite(&S{})
func Test(t *testing.T) { check.TestingT(t) }
func (s *S) TestOsExecutorImplementsExecutor(c *check.C) {
var _ Executor = OsExecutor{}
}
func (s *S) TestExecute(c *check.C) {
tmpdir, err := commandmocker.Add("ls", "ok")
c.Assert(err, check.IsNil)
defer commandmocker.Remove(tmpdir)
var e OsExecutor
var b bytes.Buffer
opts := ExecuteOptions{
Cmd: "ls",
Args: []string{"-lsa"},
Stdout: &b,
Stderr: &b,
}
err = e.Execute(opts)
c.Assert(err, check.IsNil)
c.Assert(commandmocker.Ran(tmpdir), check.Equals, true)
expected := []string{"-lsa"}
c.Assert(commandmocker.Parameters(tmpdir), check.DeepEquals, expected)
c.Assert(b.String(), check.Equals, "ok")
}
func (s *S) TestExecuteWithoutArgs(c *check.C) {
tmpdir, err := commandmocker.Add("ls", "ok")
c.Assert(err, check.IsNil)
defer commandmocker.Remove(tmpdir)
var e OsExecutor
var b bytes.Buffer
opts := ExecuteOptions{
Cmd: "ls",
Stdout: &b,
Stderr: &b,
}
err = e.Execute(opts)
c.Assert(err, check.IsNil)
c.Assert(commandmocker.Ran(tmpdir), check.Equals, true)
c.Assert(commandmocker.Parameters(tmpdir), check.IsNil)
c.Assert(b.String(), check.Equals, "ok")
}