66 gson "github.com/bitly/go-simplejson"
77 "github.com/deis/deis/tests/utils"
88 "os/exec"
9+ "strings"
910 "testing"
1011 "text/template"
1112)
@@ -30,14 +31,15 @@ func SetUser() *UserDetails {
3031 var user = new (UserDetails )
3132 user .UserName , user .Password = utils .GetUserDetails ()
3233 user .Email = "test@test.co.nz"
34+ user .HostName = "deis.54.193.35.8.xip.io"
3335 return user
3436}
3537
3638func GlobalSetup (t * testing.T ) * DeisTestConfig {
3739 var envCfg = DeisTestConfig {
3840 "~/.ssh/deis" ,
39- "54.193.41.120 " ,
40- "deis.54.193.9.175 .xip.io" ,
41+ "54.193.35.8 " ,
42+ "deis.54.193.35.8 .xip.io" ,
4143 "~/.vagrant.d/insecure_private_key" ,
4244 }
4345 var user = UserDetails {
@@ -46,10 +48,19 @@ func GlobalSetup(t *testing.T) *DeisTestConfig {
4648 "test@test.co.nz" ,
4749 envCfg .HostName ,
4850 }
49- Execute (t , GetCommand ("auth" , "register" ), user , false )
51+ Execute (t , GetCommand ("auth" , "register" ), user , false , "" )
5052 return & envCfg
5153}
5254
55+ /***Execute function takes command string and parameters required to execute the command
56+ A failflag to check whether the command is expected to fail
57+ An expect string to check whether the command has failed according to failflag
58+
59+ If a failflag is true and command failed we check the stdout and stderr for expect string
60+
61+ ***/
62+
63+
5364func Execute (t * testing.T , cmd string , params interface {}, failFlag bool , expect string ) {
5465 var cmdBuf bytes.Buffer
5566 tmpl := template .Must (template .New ("cmd" ).Parse (cmd ))
@@ -59,19 +70,33 @@ func Execute(t *testing.T, cmd string, params interface{}, failFlag bool, expect
5970 cmdString := cmdBuf .String ()
6071 fmt .Println (cmdString )
6172 cmdl := exec .Command ("sh" , "-c" , Deis + cmdString )
62- if err := utils .RunCommandWithStdoutStderr (cmdl ); err != nil {
63- if failFlag {
64- fmt .Println ("Test Failed expected behavior " )
73+
74+ switch failFlag {
75+ case true :
76+ if stdout , stderr , err := utils .RunCommandWithStdoutStderr (cmdl ); err != nil {
77+ if strings .Contains (stdout .String (), expect ) || strings .Contains (stderr .String (), expect ) {
78+ fmt .Println ("Test Failed Expected behavior" )
79+ } else {
80+ t .Fatalf ("Failed:\n %v" , err )
81+ }
6582 } else {
66- t .Fatalf ("Output:\n %v" , err )
83+ if strings .Contains (stdout .String (), expect ) || strings .Contains (stderr .String (), expect ) {
84+ fmt .Println ("expected" + expect )
85+ } else {
86+ t .Fatalf ("Failed:\n %v" , err )
87+ }
88+ }
89+ case false :
90+ if _ , _ , err := utils .RunCommandWithStdoutStderr (cmdl ); err != nil {
91+ t .Fatalf ("Failed:\n %v" , err )
92+ } else {
93+ fmt .Println ("ok" )
6794 }
68- } else if failFlag {
69- t .Fatalf ("test should be failed here but passing " )
70- } else {
71- fmt .Println ("ok" )
7295 }
7396}
7497
98+
99+
75100func GetCommand (cmdtype , cmd string ) string {
76101 js , _ := gson .NewJson (utils .GetFileBytes ("testconfig.json" ))
77102 command , _ := js .Get ("commands" ).Get (cmdtype ).Get (cmd ).String ()
0 commit comments