mirror of
				https://github.com/redhat-developer/odo.git
				synced 2025-10-19 03:06:19 +03:00 
			
		
		
		
	Exit a test early if a session has exited (#6711)
Signed-off-by: Parthvi Vala <pvala@redhat.com>
This commit is contained in:
		| @@ -176,6 +176,9 @@ func (o DevSession) Kill() { | ||||
|  | ||||
| // Stop a Dev session cleanly (equivalent as hitting Ctrl-c) | ||||
| func (o *DevSession) Stop() { | ||||
| 	if o.session == nil { | ||||
| 		return | ||||
| 	} | ||||
| 	if o.console != nil { | ||||
| 		err := o.console.Close() | ||||
| 		gomega.Expect(err).NotTo(gomega.HaveOccurred()) | ||||
| @@ -183,13 +186,14 @@ func (o *DevSession) Stop() { | ||||
| 	if o.stopped { | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	err := terminateProc(o.session) | ||||
| 	gomega.Expect(err).NotTo(gomega.HaveOccurred()) | ||||
| 	o.stopped = true | ||||
| } | ||||
|  | ||||
| func (o *DevSession) PressKey(p byte) { | ||||
| 	if o.console == nil { | ||||
| 	if o.console == nil || o.session == nil { | ||||
| 		return | ||||
| 	} | ||||
| 	_, err := o.console.Write([]byte{p}) | ||||
| @@ -197,6 +201,9 @@ func (o *DevSession) PressKey(p byte) { | ||||
| } | ||||
|  | ||||
| func (o DevSession) WaitEnd() { | ||||
| 	if o.session == nil { | ||||
| 		return | ||||
| 	} | ||||
| 	o.session.Wait(3 * time.Minute) | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -42,10 +42,13 @@ func CmdRunner(program string, args ...string) *gexec.Session { | ||||
| 	return session | ||||
| } | ||||
|  | ||||
| // WaitForOutputToContain waits for the session stdout output to contain a particular substring | ||||
| // WaitForOutputToContain waits for the session stdout output to contain a particular substring; | ||||
| // if the session exits, it checks for the substring and returns early | ||||
| func WaitForOutputToContain(substring string, timeoutInSeconds int, intervalInSeconds int, session *gexec.Session) { | ||||
|  | ||||
| 	Eventually(func() string { | ||||
| 		if session.ExitCode() != -1 { | ||||
| 			Expect(string(session.Out.Contents())).To(ContainSubstring(substring), "session exited, but substring not found") | ||||
| 		} | ||||
| 		contents := string(session.Out.Contents()) | ||||
| 		return contents | ||||
| 	}, timeoutInSeconds, intervalInSeconds).Should(ContainSubstring(substring)) | ||||
| @@ -59,15 +62,22 @@ func WaitForOutputToContainOne(substrings []string, timeoutInSeconds int, interv | ||||
| 		matchers = append(matchers, ContainSubstring(substring)) | ||||
| 	} | ||||
| 	Eventually(func() string { | ||||
| 		if session.ExitCode() != -1 { | ||||
| 			Expect(string(session.Out.Contents())).To(SatisfyAny(matchers...), "session exited, but substring not found") | ||||
| 		} | ||||
| 		contents := string(session.Out.Contents()) | ||||
| 		return contents | ||||
| 	}, timeoutInSeconds, intervalInSeconds).Should(SatisfyAny(matchers...)) | ||||
| } | ||||
|  | ||||
| // WaitForErroutToContain waits for the session stdout output to contain a particular substring | ||||
| // if the session exits, it checks for the substring and returns early | ||||
| func WaitForErroutToContain(substring string, timeoutInSeconds int, intervalInSeconds int, session *gexec.Session) { | ||||
|  | ||||
| 	Eventually(func() string { | ||||
| 		if session.ExitCode() != -1 { | ||||
| 			Expect(string(session.Err.Contents())).To(ContainSubstring(substring), "session exited, but substring not found") | ||||
| 		} | ||||
| 		contents := string(session.Err.Contents()) | ||||
| 		return contents | ||||
| 	}, timeoutInSeconds, intervalInSeconds).Should(ContainSubstring(substring)) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Parthvi Vala
					Parthvi Vala