@@ -3,6 +3,7 @@ package itutils
33import (
44 "bytes"
55 "fmt"
6+ "github.com/ThomasRooney/gexpect"
67 gson "github.com/bitly/go-simplejson"
78 "github.com/deis/deis/tests/utils"
89 "io/ioutil"
@@ -13,7 +14,6 @@ import (
1314 "testing"
1415 "text/template"
1516 "time"
16- "github.com/ThomasRooney/gexpect"
1717)
1818
1919var Deis = "/usr/local/bin/deis "
@@ -33,7 +33,7 @@ type DeisTestConfig struct {
3333 ProcessNum string
3434 ImageId string
3535 Version string
36- AppUser string
36+ AppUser string
3737}
3838
3939func GetGlobalConfig () * DeisTestConfig {
@@ -57,24 +57,28 @@ func GetGlobalConfig() *DeisTestConfig {
5757 return & envCfg
5858}
5959
60- func Curl (t * testing.T , url string , exampleApp string ) {
60+ //Tests example apps are running or not
61+
62+ func Curl (t * testing.T , params * DeisTestConfig ) {
63+ url := "http://" + params .AppName + "." + params .HostName
6164 response , err := http .Get (url )
6265 if err != nil {
6366 t .Fatalf ("not reachable:\n %v" , err )
6467 }
6568 body , err := ioutil .ReadAll (response .Body )
6669 fmt .Println (string (body ))
67- if exampleApp == "example-python-django" {
70+ if params . AppName == "example-python-django" {
6871 if ! strings .Contains (string (body ), "Powered by django" ) {
6972 t .Fatalf ("App not started" )
7073 }
71- }else if ! strings .Contains (string (body ), "Powered by Deis" ) {
74+ } else if ! strings .Contains (string (body ), "Powered by Deis" ) {
7275 t .Fatalf ("App not started" )
7376 }
7477}
7578
79+ //gexpect implementation of auth cancel
7680
77- func AuthCancel (t * testing.T , params * DeisTestConfig ){
81+ func AuthCancel (t * testing.T , params * DeisTestConfig ) {
7882 fmt .Println ("deis auth:cancel" )
7983 child , err := gexpect .Spawn ("/usr/local/bin/deis auth:cancel" )
8084 if err != nil {
@@ -105,15 +109,23 @@ func AuthCancel(t *testing.T, params *DeisTestConfig){
105109
106110}
107111
108- func CheckList (t * testing.T , params interface {}, cmd , contain string ,notflag bool ) {
112+ /*CheckList takes config , command to execute and contain string and notflag .
113+ * Executes the command and checks if the contain string should be present or not according to notflag */
114+
115+ func CheckList (t * testing.T , params interface {}, cmd , contain string , notflag bool ) {
109116 var cmdBuf bytes.Buffer
110117 tmpl := template .Must (template .New ("cmd" ).Parse (cmd ))
111118 if err := tmpl .Execute (& cmdBuf , params ); err != nil {
112119 t .Fatal (err )
113120 }
114121 cmdString := cmdBuf .String ()
115122 fmt .Println (cmdString )
116- cmdl := exec .Command ("sh" , "-c" , Deis + cmdString )
123+ var cmdl * exec.Cmd
124+ if strings .Contains (cmd , "cat" ) {
125+ cmdl = exec .Command ("sh" , "-c" , cmdString )
126+ } else {
127+ cmdl = exec .Command ("sh" , "-c" , Deis + cmdString )
128+ }
117129 if stdout , _ , err := utils .RunCommandWithStdoutStderr (cmdl ); err == nil {
118130 if strings .Contains (stdout .String (), contain ) != notflag {
119131 fmt .Println ("Command Executed perfectly" )
@@ -172,6 +184,8 @@ func Execute(t *testing.T, cmd string, params interface{}, failFlag bool, expect
172184 }
173185}
174186
187+ //Destroys an app after execution of each integration test
188+
175189func AppsDestroyTest (t * testing.T , params * DeisTestConfig ) {
176190 cmd := GetCommand ("apps" , "destroy" )
177191 if err := utils .Chdir (params .ExampleApp ); err != nil {
@@ -186,12 +200,15 @@ func AppsDestroyTest(t *testing.T, params *DeisTestConfig) {
186200 }
187201}
188202
203+ //Fetch commands from testconfig.json
204+
189205func GetCommand (cmdtype , cmd string ) string {
190206 js , _ := gson .NewJson (utils .GetFileBytes ("testconfig.json" ))
191207 command , _ := js .Get ("commands" ).Get (cmdtype ).Get (cmd ).String ()
192208 return command
193209}
194210
211+ //Selects a random app
195212
196213func GetRandomApp () string {
197214 s1 := rand .NewSource (int64 (time .Now ().Unix ()))
@@ -200,13 +217,12 @@ func GetRandomApp() string {
200217 appmap [0 ] = "example-go"
201218 appmap [1 ] = "example-ruby-sinatra"
202219 appmap [2 ] = "example-java-jetty"
203- appmap [3 ] = "example-play"
204- appmap [4 ] = "example-nodejs-express"
205- appmap [5 ] = "example-python-flask"
206- appmap [6 ] = "example-dockerfile-python"
207- appmap [7 ] = "example-scala"
208- appmap [8 ] = "example-clojure-ring"
209- appmap [9 ] = "example-python-django"
210- app := appmap [r1 .Intn (9 )]
220+ appmap [3 ] = "example-nodejs-express"
221+ appmap [4 ] = "example-python-flask"
222+ appmap [5 ] = "example-dockerfile-python"
223+ appmap [6 ] = "example-scala"
224+ appmap [7 ] = "example-clojure-ring"
225+ appmap [8 ] = "example-python-django"
226+ app := appmap [r1 .Intn (8 )]
211227 return app
212228}
0 commit comments