2014-03-20 13:18:03 +00:00
|
|
|
package deploy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2014-06-04 21:25:38 +00:00
|
|
|
"github.com/drone/drone/shared/build/buildfile"
|
2014-03-20 13:18:03 +00:00
|
|
|
|
2014-06-12 21:38:12 +00:00
|
|
|
"gopkg.in/yaml.v1"
|
2014-03-20 13:18:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// emulate Build struct
|
|
|
|
type buildWithBash struct {
|
|
|
|
Deploy *Deploy `yaml:"deploy,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
var sampleYmlWithBash = `
|
|
|
|
deploy:
|
|
|
|
bash:
|
|
|
|
command: 'echo bash_deployed'
|
|
|
|
`
|
|
|
|
|
|
|
|
var sampleYmlWithScript = `
|
|
|
|
deploy:
|
|
|
|
bash:
|
|
|
|
script:
|
|
|
|
- ./bin/deploy.sh
|
|
|
|
- ./bin/check.sh
|
|
|
|
`
|
|
|
|
|
|
|
|
var sampleYmlWithBashAndScript = `
|
|
|
|
deploy:
|
|
|
|
bash:
|
|
|
|
command: ./bin/some_cmd.sh
|
|
|
|
script:
|
|
|
|
- ./bin/deploy.sh
|
|
|
|
- ./bin/check.sh
|
|
|
|
`
|
|
|
|
|
|
|
|
func setUpWithBash(input string) (string, error) {
|
|
|
|
var buildStruct buildWithBash
|
2014-06-12 21:38:12 +00:00
|
|
|
err := yaml.Unmarshal([]byte(input), &buildStruct)
|
2014-03-20 13:18:03 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
bf := buildfile.New()
|
|
|
|
buildStruct.Deploy.Write(bf)
|
|
|
|
return bf.String(), err
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBashDeployment(t *testing.T) {
|
|
|
|
bscr, err := setUpWithBash(sampleYmlWithBash)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Can't unmarshal deploy script: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(bscr, "echo bash_deployed") {
|
|
|
|
t.Error("Expect script to contains bash command")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBashDeploymentWithScript(t *testing.T) {
|
|
|
|
bscr, err := setUpWithBash(sampleYmlWithScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Can't unmarshal deploy script: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(bscr, "./bin/deploy.sh") {
|
|
|
|
t.Error("Expect script to contains bash script")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(bscr, "./bin/check.sh") {
|
|
|
|
t.Error("Expect script to contains bash script")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBashDeploymentWithBashAndScript(t *testing.T) {
|
|
|
|
bscr, err := setUpWithBash(sampleYmlWithBashAndScript)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Can't unmarshal deploy script: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(bscr, "./bin/deploy.sh") {
|
|
|
|
t.Error("Expect script to contains bash script")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(bscr, "./bin/check.sh") {
|
|
|
|
t.Error("Expect script to contains bash script")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(bscr, "./bin/some_cmd.sh") {
|
|
|
|
t.Error("Expect script to contains bash script")
|
|
|
|
}
|
|
|
|
}
|