github.com/marinho/drone@v0.2.1-0.20140504195434-d3ba962e89a7/pkg/plugin/deploy/cloudfoundry_test.go (about) 1 package deploy 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/drone/drone/pkg/build/buildfile" 8 9 "launchpad.net/goyaml" 10 ) 11 12 // emulate Build struct 13 type DeployToCF struct { 14 Deploy *Deploy `yaml:"deploy,omitempty"` 15 } 16 17 var sampleYmlBasic = ` 18 deploy: 19 cloudfoundry: 20 target: https://api.example.com 21 username: foo 22 password: bar 23 ` 24 25 var sampleYmlWithOrg = ` 26 deploy: 27 cloudfoundry: 28 target: https://api.example.com 29 username: foo 30 password: bar 31 org: custom-org 32 ` 33 34 var sampleYmlWithSpace = ` 35 deploy: 36 cloudfoundry: 37 target: https://api.example.com 38 username: foo 39 password: bar 40 org: custom-org 41 space: dev 42 ` 43 44 var sampleYmlWithAppName = ` 45 deploy: 46 cloudfoundry: 47 target: https://api.example.com 48 username: foo 49 password: bar 50 app: test-app 51 ` 52 53 func setUpWithCF(input string) (string, error) { 54 var buildStruct DeployToCF 55 err := goyaml.Unmarshal([]byte(input), &buildStruct) 56 if err != nil { 57 return "", err 58 } 59 bf := buildfile.New() 60 buildStruct.Deploy.Write(bf) 61 return bf.String(), err 62 } 63 64 func TestCloudFoundryToolInstall(t *testing.T) { 65 bscr, err := setUpWithCF(sampleYmlBasic) 66 if err != nil { 67 t.Fatalf("Can't unmarshal deploy script: %s", err) 68 } 69 70 if !strings.Contains(bscr, "curl -sLO http://go-cli.s3-website-us-east-1.amazonaws.com/releases/latest/cf-cli_amd64.deb") { 71 t.Error("Expect script to contain download command") 72 } 73 74 if !strings.Contains(bscr, "dpkg -i cf-cli_amd64.deb") { 75 t.Error("Expect script to contain install command") 76 } 77 } 78 79 func TestCloudFoundryDeployment(t *testing.T) { 80 bscr, err := setUpWithCF(sampleYmlBasic) 81 if err != nil { 82 t.Fatalf("Can't unmarshal deploy script: %s", err) 83 } 84 85 if !strings.Contains(bscr, "cf login -a https://api.example.com -u foo -p bar") { 86 t.Error("Expect login script to contain username and password") 87 } 88 89 if !strings.Contains(bscr, "cf push") { 90 t.Error("Expect script to contain push") 91 } 92 } 93 94 func TestCloudFoundryDeploymentWithOrg(t *testing.T) { 95 bscr, err := setUpWithCF(sampleYmlWithOrg) 96 if err != nil { 97 t.Fatalf("Can't unmarshal deploy script: %s", err) 98 } 99 100 if !strings.Contains(bscr, "cf login -a https://api.example.com -u foo -p bar -o custom-org") { 101 t.Error("Expect login script to contain organization") 102 } 103 } 104 105 func TestCloudFoundryDeploymentWithSpace(t *testing.T) { 106 bscr, err := setUpWithCF(sampleYmlWithSpace) 107 if err != nil { 108 t.Fatalf("Can't unmarshal deploy script: %s", err) 109 } 110 111 if !strings.Contains(bscr, "cf login -a https://api.example.com -u foo -p bar -o custom-org -s dev") { 112 t.Error("Expect login script to contain space") 113 } 114 } 115 116 func TestCloudFoundryDeploymentWithApp(t *testing.T) { 117 bscr, err := setUpWithCF(sampleYmlWithAppName) 118 if err != nil { 119 t.Fatalf("Can't unmarshal deploy script: %s", err) 120 } 121 122 if !strings.Contains(bscr, "cf push test-app") { 123 t.Error("Expect login script to contain app name") 124 } 125 }