+func TestTarget(t *testing.T) {
+ nbTargets := 3
+ nbTermsByTarget := 3
+ /*channel for target events*/
+ chTarget := make(chan xsapiv1.TargetConfig)
+ defer close(chTarget)
+ ConnectTargetEvents(t, chTarget)
+
+ /*channel for terminal events*/
+ chTermEvt := make(chan xsapiv1.TerminalConfig)
+ defer close(chTermEvt)
+ ConnectTermEvents(t, chTermEvt)
+
+ /*check that targetArray is empty at startup*/
+ var targetArray []xsapiv1.TargetConfig
+ assert.Nil(t, HTTPCli.Get("/targets", &targetArray))
+ assert.Equal(t, len(targetArray), 0)
+
+ listID := AddTargets(t, nbTargets, chTarget)
+ AddTerms(t, nbTermsByTarget, listID, chTermEvt)
+
+ ///*channel for TerminalOutMsg*/
+ //chTerm := make(chan xsapiv1.TerminalOutMsg)
+ //defer close(chTerm)
+
+ ///*connect on terminalOutMsg event*/
+ //sCli.Conn.On(xsapiv1.TerminalOutEvent, func(ev xsapiv1.TerminalOutMsg) {
+ // chTerm <- ev
+ //})
+
+ ///*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)
+ //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
+ //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)
+ //totoFile := path.Join(rootCfgDir, "toto")
+
+ ///*test with 2 terminals*/
+ //for i := 0; i < 2; i++ {
+ // totoFileCurrent := totoFile + strconv.Itoa(i)
+ // /*send cmd though term*/
+ // data := []byte("echo helloWorld" + strconv.Itoa(i) + " >> " + totoFileCurrent + "\n")
+ // Debugf(t, "send following command through terminal: %v", string(data))
+ // assert.Nil(t, sCli.Conn.Emit(xsapiv1.TerminalInEvent, data))
+ // flushChannelTerm(chTerm, 50) //waiting for terminal msg
+
+ // /*check that toto file is created*/
+ // _, err := os.Stat(totoFileCurrent)
+ // assert.Nil(t, err)
+
+ // /*send cmd though term*/
+ // data = []byte("cat " + totoFileCurrent + "\n")
+ // Debugf(t, "send following command through terminal: %v", string(data))
+ // assert.Nil(t, sCli.Conn.Emit(xsapiv1.TerminalInEvent, data))
+
+ // <-chTerm //cmd sent
+ // termOut = <-chTerm //result of cat cmd
+ // flushChannelTerm(chTerm, 50) //flushing what remains
+ // /*check that terminal msg is what was written before*/
+ // assert.Equal(t, string(termOut.Stdout), "helloWorld"+strconv.Itoa(i)+"\r\n")
+ // Debugf(t, "check terminal output msg: %v", string(termOut.Stdout))
+ //}
+
+ //PostTerms(t, "close", chTermEvt)
+
+ /*remove targets and terms*/
+ RemoveTermsTargets(t, chTarget, chTermEvt)
+ DisconnectTargetEvents(t)
+ DisconnectTermEvents(t)
+}