github.com/unclejack/drone@v0.2.1-0.20140918182345-831b034aa33b/pkg/plugin/deploy/bash_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 buildWithBash struct { 14 Deploy *Deploy `yaml:"deploy,omitempty"` 15 } 16 17 var sampleYmlWithBash = ` 18 deploy: 19 bash: 20 command: 'echo bash_deployed' 21 ` 22 23 var sampleYmlWithScript = ` 24 deploy: 25 bash: 26 script: 27 - ./bin/deploy.sh 28 - ./bin/check.sh 29 ` 30 31 var sampleYmlWithBashAndScript = ` 32 deploy: 33 bash: 34 command: ./bin/some_cmd.sh 35 script: 36 - ./bin/deploy.sh 37 - ./bin/check.sh 38 ` 39 40 func setUpWithBash(input string) (string, error) { 41 var buildStruct buildWithBash 42 err := goyaml.Unmarshal([]byte(input), &buildStruct) 43 if err != nil { 44 return "", err 45 } 46 bf := buildfile.New() 47 buildStruct.Deploy.Write(bf) 48 return bf.String(), err 49 } 50 51 func TestBashDeployment(t *testing.T) { 52 bscr, err := setUpWithBash(sampleYmlWithBash) 53 if err != nil { 54 t.Fatalf("Can't unmarshal deploy script: %s", err) 55 } 56 57 if !strings.Contains(bscr, "echo bash_deployed") { 58 t.Error("Expect script to contains bash command") 59 } 60 } 61 62 func TestBashDeploymentWithScript(t *testing.T) { 63 bscr, err := setUpWithBash(sampleYmlWithScript) 64 if err != nil { 65 t.Fatalf("Can't unmarshal deploy script: %s", err) 66 } 67 68 if !strings.Contains(bscr, "./bin/deploy.sh") { 69 t.Error("Expect script to contains bash script") 70 } 71 72 if !strings.Contains(bscr, "./bin/check.sh") { 73 t.Error("Expect script to contains bash script") 74 } 75 } 76 77 func TestBashDeploymentWithBashAndScript(t *testing.T) { 78 bscr, err := setUpWithBash(sampleYmlWithBashAndScript) 79 if err != nil { 80 t.Fatalf("Can't unmarshal deploy script: %s", err) 81 } 82 83 if !strings.Contains(bscr, "./bin/deploy.sh") { 84 t.Error("Expect script to contains bash script") 85 } 86 87 if !strings.Contains(bscr, "./bin/check.sh") { 88 t.Error("Expect script to contains bash script") 89 } 90 91 if !strings.Contains(bscr, "./bin/some_cmd.sh") { 92 t.Error("Expect script to contains bash script") 93 } 94 }