}
/*add target*/
assert.Nil(t, HTTPCli.Post("/targets", target, &target))
+ t.Logf("add target %v", target.Name)
targetEvt := <-chTarget //waiting for event targetAdd
assert.Equal(t, target.ID, targetEvt.ID)
listID[i] = target.ID
}
/*add terminal on target*/
assert.Nil(t, HTTPCli.Post("/targets/"+listID[j]+"/terminals", term, &term))
+ t.Logf("add terminal %v", term.Name)
termEvt := <-chTermEvt //waiting for event terminalAdd*/
assert.Equal(t, term.ID, termEvt.ID)
listTermsID[i] = term.ID
listTermsID := make([]string, len(terms))
for j := 0; j < len(terms); j++ {
var term xsapiv1.TerminalConfig
+ /*post action on term*/
assert.Nil(t, HTTPCli.Post("/targets/"+targets[i].ID+"/terminals/"+terms[j].ID+"/"+post, terms[j], &term))
+ t.Logf("%v terminal %v", post, term.Name)
termEvt := <-chTermEvt //waiting for event terminalStateChange
assert.Equal(t, term.ID, termEvt.ID)
assert.Equal(t, term.Status, status)
var term xsapiv1.TerminalConfig
assert.Nil(t, HTTPCli.Get("/targets/"+targets[i].ID+"/terminals/"+listTermsID[i], &term))
assert.True(t, strings.EqualFold(term.Status, post))
+ t.Logf("check that term status %v is %v", term.Name, post)
}
}
}
termEvt := <-chTermEvt
assert.Equal(t, term.ID, termEvt.ID)
assert.NotNil(t, HTTPCli.Delete("/targets/"+targets[i].ID+"/terminals/"+terms[j].ID, &term))
+ t.Logf("remove terminal %v", term.Name)
}
var tgtRes xsapiv1.TargetConfig
assert.Nil(t, HTTPCli.Delete("/targets/"+targets[i].ID, &tgtRes))
- targetEvt := <-chTarget
+ targetEvt := <-chTarget //waiting for remove terminal event
assert.Equal(t, tgtRes.ID, targetEvt.ID)
assert.Equal(t, targets[i].ID, tgtRes.ID)
}
chTerm <- ev
})
- /*open first term*/
+ /*open terminals*/
PostTerms(t, "open", chTermEvt)
/*just for the first term*/
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)
/*create toto file through terminals*/
rootCfgDir := os.Getenv(envRootCfgDir)
totoFileCurrent := totoFile + strconv.Itoa(i)
/*send cmd though term*/
data := []byte("echo helloWorld" + strconv.Itoa(i) + " >> " + totoFileCurrent + "\n")
+ t.Logf("send following command through terminal: %v", string(data))
assert.Nil(t, sCli.Conn.Emit(xsapiv1.TerminalInEvent, data))
flushChannelTerm(chTerm, 50) //waiting for terminal msg
/*send cmd though term*/
data = []byte("cat " + totoFileCurrent + "\n")
+ t.Logf("send following command through terminal: %v", string(data))
assert.Nil(t, sCli.Conn.Emit(xsapiv1.TerminalInEvent, data))
<-chTerm //cmd sent
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")
+ t.Logf("check terminal output msg: %v", string(termOut.Stdout))
}
PostTerms(t, "close", chTermEvt)
}
func TestTargetErrors(t *testing.T) {
+ /*cannot create empty target*/
target := xsapiv1.TargetConfig{}
var targetRes xsapiv1.TargetConfig
assert.NotNil(t, HTTPCli.Post("/targets", target, &targetRes))
+ t.Logf("error while creating empty target")
+ /*check cannot create target with no IP*/
target.Type = xsapiv1.TypeTgtStandard
assert.NotNil(t, HTTPCli.Post("/targets", target, &targetRes))
+ t.Logf("error while creating target without IP")
target.IP = "127.0.0.1"
assert.Nil(t, HTTPCli.Post("/targets", target, &targetRes))
+ t.Logf("create target %v", targetRes.Name)
+ /*cannot create empty terminal*/
term := xsapiv1.TerminalConfig{}
var termRes xsapiv1.TerminalConfig
assert.NotNil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
+ t.Logf("error while creating empty terminal")
term.Type = xsapiv1.TypeTermSSH
assert.NotNil(t, HTTPCli.Post("/targets/"+"1010"+"/terminals", term, &termRes))
+ t.Logf("error while creating terminal on an non existing target")
assert.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
assert.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
assert.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
assert.Nil(t, HTTPCli.Post("/targets/"+targetRes.ID+"/terminals", term, &termRes))
+ t.Logf("create several terminals")
/*remove targets and terms*/
var targetArray []xsapiv1.TargetConfig
assert.Nil(t, HTTPCli.Get("/targets/"+targetArray[i].ID+"/terminals", &termArray))
for j := 0; j < len(termArray); j++ {
assert.Nil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID+"/terminals/"+termArray[j].ID, &termRes))
+ t.Logf("delete terminal %v", termRes.Name)
assert.NotNil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID+"/terminals/"+termArray[j].ID, &termRes))
+ t.Logf("error while deleting an already deleted terminal %v", termRes.Name)
}
var tgtRes xsapiv1.TargetConfig
assert.Nil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID, &tgtRes))
+ t.Logf("delete target %v", tgtRes.Name)
assert.Equal(t, targetArray[i].ID, tgtRes.ID)
assert.NotNil(t, HTTPCli.Delete("/targets/"+targetArray[i].ID, &tgtRes))
+ t.Logf("error while deleting an already deleted target %v", tgtRes.Name)
}
}