~ubuntu-branches/ubuntu/vivid/juju-core/vivid-updates

« back to all changes in this revision

Viewing changes to src/github.com/juju/utils/shell/script_test.go

  • Committer: Package Import Robot
  • Author(s): Curtis C. Hovey
  • Date: 2015-09-29 19:43:29 UTC
  • mfrom: (47.1.4 wily-proposed)
  • Revision ID: package-import@ubuntu.com-20150929194329-9y496tbic30hc7vp
Tags: 1.24.6-0ubuntu1~15.04.1
Backport of 1.24.6 from wily. (LP: #1500916, #1497087)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
        "strings"
13
13
 
14
14
        "github.com/juju/testing"
 
15
        jc "github.com/juju/testing/checkers"
15
16
        gc "gopkg.in/check.v1"
16
17
 
17
18
        "github.com/juju/utils/shell"
69
70
        c.Assert(stdout, gc.Equals, "")
70
71
        c.Assert(stderr, gc.Equals, "")
71
72
}
 
73
 
 
74
func (*scriptSuite) TestWriteScriptUnix(c *gc.C) {
 
75
        renderer := &shell.BashRenderer{}
 
76
        script := `
 
77
exec a-command
 
78
exec another-command
 
79
`
 
80
        commands := shell.WriteScript(renderer, "spam", "/ham/eggs", strings.Split(script, "\n"))
 
81
 
 
82
        cmd := `
 
83
cat > '/ham/eggs/spam.sh' << 'EOF'
 
84
#!/usr/bin/env bash
 
85
 
 
86
 
 
87
exec a-command
 
88
exec another-command
 
89
 
 
90
EOF`[1:]
 
91
        c.Check(commands, jc.DeepEquals, []string{
 
92
                cmd,
 
93
                "chmod 0755 '/ham/eggs/spam.sh'",
 
94
        })
 
95
}
 
96
 
 
97
func (*scriptSuite) TestWriteScriptWindows(c *gc.C) {
 
98
        renderer := &shell.PowershellRenderer{}
 
99
        script := `
 
100
exec a-command
 
101
exec another-command
 
102
`
 
103
        commands := shell.WriteScript(renderer, "spam", `C:\ham\eggs`, strings.Split(script, "\n"))
 
104
 
 
105
        c.Check(commands, jc.DeepEquals, []string{
 
106
                `Set-Content 'C:\ham\eggs\spam.ps1' @"
 
107
 
 
108
exec a-command
 
109
exec another-command
 
110
 
 
111
"@`,
 
112
        })
 
113
}