diff options
Diffstat (limited to 'test/target_test.go')
-rw-r--r-- | test/target_test.go | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/test/target_test.go b/test/target_test.go index e222505..0fcd94d 100644 --- a/test/target_test.go +++ b/test/target_test.go @@ -111,6 +111,7 @@ func AddTargets(t *testing.T, nbTargets int, chTarget chan xsapiv1.TargetConfig) } /*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 @@ -133,6 +134,7 @@ func AddTerms(t *testing.T, nbTerms int, listID []string, chTermEvt chan xsapiv1 } /*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 @@ -162,7 +164,9 @@ func PostTerms(t *testing.T, post string, chTermEvt chan xsapiv1.TerminalConfig) 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) @@ -174,6 +178,7 @@ func PostTerms(t *testing.T, post string, chTermEvt chan xsapiv1.TerminalConfig) 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) } } } @@ -190,10 +195,11 @@ func RemoveTermsTargets(t *testing.T, chTarget chan xsapiv1.TargetConfig, chTerm 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) } @@ -228,7 +234,7 @@ func TestTarget(t *testing.T) { chTerm <- ev }) - /*open first term*/ + /*open terminals*/ PostTerms(t, "open", chTermEvt) /*just for the first term*/ @@ -241,6 +247,7 @@ 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) /*create toto file through terminals*/ rootCfgDir := os.Getenv(envRootCfgDir) @@ -251,6 +258,7 @@ func TestTarget(t *testing.T) { 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 @@ -260,6 +268,7 @@ func TestTarget(t *testing.T) { /*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 @@ -267,6 +276,7 @@ func TestTarget(t *testing.T) { 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) @@ -278,23 +288,32 @@ func TestTarget(t *testing.T) { } 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 @@ -304,11 +323,15 @@ func TestTargetErrors(t *testing.T) { 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) } } |