2014-03-29 20:09:16 +00:00
|
|
|
package deploy
|
|
|
|
|
|
|
|
import (
|
2014-04-20 14:35:50 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
2014-03-29 20:09:16 +00:00
|
|
|
|
2014-04-20 14:35:50 +00:00
|
|
|
"github.com/drone/drone/pkg/build/buildfile"
|
2014-03-29 20:09:16 +00:00
|
|
|
|
2014-04-20 14:35:50 +00:00
|
|
|
"launchpad.net/goyaml"
|
2014-03-29 20:09:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// emulate Build struct
|
|
|
|
type DeployToCF struct {
|
2014-04-20 14:35:50 +00:00
|
|
|
Deploy *Deploy `yaml:"deploy,omitempty"`
|
2014-03-29 20:09:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var sampleYmlBasic = `
|
|
|
|
deploy:
|
|
|
|
cloudfoundry:
|
|
|
|
target: https://api.example.com
|
|
|
|
username: foo
|
|
|
|
password: bar
|
|
|
|
`
|
|
|
|
|
|
|
|
var sampleYmlWithOrg = `
|
|
|
|
deploy:
|
|
|
|
cloudfoundry:
|
|
|
|
target: https://api.example.com
|
|
|
|
username: foo
|
|
|
|
password: bar
|
|
|
|
org: custom-org
|
|
|
|
`
|
|
|
|
|
2014-04-20 14:35:50 +00:00
|
|
|
var sampleYmlWithSpace = `
|
|
|
|
deploy:
|
|
|
|
cloudfoundry:
|
|
|
|
target: https://api.example.com
|
|
|
|
username: foo
|
|
|
|
password: bar
|
|
|
|
org: custom-org
|
|
|
|
space: dev
|
|
|
|
`
|
|
|
|
|
2014-03-29 20:09:16 +00:00
|
|
|
var sampleYmlWithAppName = `
|
|
|
|
deploy:
|
|
|
|
cloudfoundry:
|
|
|
|
target: https://api.example.com
|
|
|
|
username: foo
|
|
|
|
password: bar
|
|
|
|
app: test-app
|
|
|
|
`
|
|
|
|
|
|
|
|
func setUpWithCF(input string) (string, error) {
|
2014-04-20 14:35:50 +00:00
|
|
|
var buildStruct DeployToCF
|
|
|
|
err := goyaml.Unmarshal([]byte(input), &buildStruct)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
bf := buildfile.New()
|
|
|
|
buildStruct.Deploy.Write(bf)
|
|
|
|
return bf.String(), err
|
2014-03-29 20:09:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCloudFoundryDeployment(t *testing.T) {
|
2014-04-20 14:35:50 +00:00
|
|
|
bscr, err := setUpWithCF(sampleYmlBasic)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Can't unmarshal deploy script: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(bscr, "cf login -a https://api.example.com -u foo -p bar") {
|
|
|
|
t.Error("Expect login script to contains username and password")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(bscr, "cf push") {
|
|
|
|
t.Error("Expect script to contains push")
|
|
|
|
}
|
2014-03-29 20:09:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCloudFoundryDeploymentWithOrg(t *testing.T) {
|
2014-04-20 14:35:50 +00:00
|
|
|
bscr, err := setUpWithCF(sampleYmlWithOrg)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Can't unmarshal deploy script: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(bscr, "cf login -a https://api.example.com -u foo -p bar -o custom-org") {
|
|
|
|
t.Error("Expect login script to contains organization")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCloudFoundryDeploymentWithSpace(t *testing.T) {
|
|
|
|
bscr, err := setUpWithCF(sampleYmlWithSpace)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Can't unmarshal deploy script: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(bscr, "cf login -a https://api.example.com -u foo -p bar -o custom-org -s dev") {
|
|
|
|
t.Error("Expect login script to contains space")
|
|
|
|
}
|
2014-03-29 20:09:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCloudFoundryDeploymentWithApp(t *testing.T) {
|
2014-04-20 14:35:50 +00:00
|
|
|
bscr, err := setUpWithCF(sampleYmlWithAppName)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Can't unmarshal deploy script: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(bscr, "cf push test-app") {
|
|
|
|
t.Error("Expect login script to contains app name")
|
|
|
|
}
|
2014-03-29 20:09:16 +00:00
|
|
|
}
|