test target: open 1 terminal for connection errors
authorClément Bénier <clement.benier@iot.bzh>
Tue, 21 Aug 2018 09:06:36 +0000 (11:06 +0200)
committerClément Bénier <clement.benier@iot.bzh>
Tue, 21 Aug 2018 09:08:36 +0000 (11:08 +0200)
before opening all terminals, open just one to check there is
no ssh connection problems

Change-Id: I700a00264a96480ac4656be6338e2d728f509627
Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
test/target_test.go

index 0fcd94d..50483ff 100644 (file)
@@ -234,10 +234,12 @@ func TestTarget(t *testing.T) {
                chTerm <- ev
        })
 
-       /*open terminals*/
-       PostTerms(t, "open", chTermEvt)
-
        /*just for the first term*/
+       var terms []xsapiv1.TerminalConfig
+       var term xsapiv1.TerminalConfig
+       assert.Nil(t, HTTPCli.Get("/targets/"+listID[0]+"/terminals", &terms))
+       assert.Nil(t, HTTPCli.Post("/targets/"+listID[0]+"/terminals/"+terms[0].ID+"/open", terms[0], &term))
+       <-chTermEvt                  //waiting for event terminalStateChange
        termOut := <-chTerm          //waiting for terminalOutMsg
        flushChannelTerm(chTerm, 50) //flushing all terminalOutMsg
        stdoutMsg := string(termOut.Stdout)
@@ -247,7 +249,20 @@ func TestTarget(t *testing.T) {
                t.Fatalf("%vcopy your pub key in authorized_keys\ncat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys", stdoutMsg)
        }
        assert.True(t, strings.Contains(stdoutMsg, "Last login")) //first terminal msg should be Last Login
-       t.Logf("terminal is open, console msg is %v", stdoutMsg)
+       assert.Nil(t, HTTPCli.Post("/targets/"+listID[0]+"/terminals/"+terms[0].ID+"/close", terms[0], &term))
+       <-chTermEvt //waiting for event terminalStateChange
+
+       /*open terminals*/
+       PostTerms(t, "open", chTermEvt)
+       termOut = <-chTerm           //waiting for terminalOutMsg
+       flushChannelTerm(chTerm, 50) //flushing all terminalOutMsg
+       stdoutMsg = string(termOut.Stdout)
+       if strings.Contains(stdoutMsg, "Connection refused") {
+               t.Fatalf("%vYou may have to launch ssh server", stdoutMsg)
+       } else if strings.Contains(stdoutMsg, "password") {
+               t.Fatalf("%vcopy your pub key in authorized_keys\ncat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys", stdoutMsg)
+       }
+       assert.True(t, strings.Contains(stdoutMsg, "Last login")) //first terminal msg should be Last Login
 
        /*create toto file through terminals*/
        rootCfgDir := os.Getenv(envRootCfgDir)