mirror of https://github.com/docker/docs.git
				
				
				
			Test distinguish stdout from stderr
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
This commit is contained in:
		
							parent
							
								
									854219d44a
								
							
						
					
					
						commit
						aa9ff22395
					
				|  | @ -78,11 +78,12 @@ func TestLocalBinaryPluginClose(t *testing.T) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestExecServer(t *testing.T) { | func TestExecServer(t *testing.T) { | ||||||
| 	logReader, logWriter := io.Pipe() | 	logOutReader, logOutWriter := io.Pipe() | ||||||
|  | 	logErrReader, logErrWriter := io.Pipe() | ||||||
| 
 | 
 | ||||||
| 	log.SetDebug(true) | 	log.SetDebug(true) | ||||||
| 	log.SetOutWriter(logWriter) | 	log.SetOutWriter(logOutWriter) | ||||||
| 	log.SetErrWriter(logWriter) | 	log.SetErrWriter(logErrWriter) | ||||||
| 
 | 
 | ||||||
| 	defer func() { | 	defer func() { | ||||||
| 		log.SetDebug(false) | 		log.SetDebug(false) | ||||||
|  | @ -113,7 +114,8 @@ func TestExecServer(t *testing.T) { | ||||||
| 		finalErr <- lbp.execServer() | 		finalErr <- lbp.execServer() | ||||||
| 	}() | 	}() | ||||||
| 
 | 
 | ||||||
| 	logScanner := bufio.NewScanner(logReader) | 	logOutScanner := bufio.NewScanner(logOutReader) | ||||||
|  | 	logErrScanner := bufio.NewScanner(logErrReader) | ||||||
| 
 | 
 | ||||||
| 	// Write the ip address
 | 	// Write the ip address
 | ||||||
| 	expectedAddr := "127.0.0.1:12345" | 	expectedAddr := "127.0.0.1:12345" | ||||||
|  | @ -132,8 +134,8 @@ func TestExecServer(t *testing.T) { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	expectedOut := fmt.Sprintf(pluginOut, machineName, expectedPluginOut) | 	expectedOut := fmt.Sprintf(pluginOut, machineName, expectedPluginOut) | ||||||
| 	if logScanner.Scan(); logScanner.Text() != expectedOut { | 	if logOutScanner.Scan(); logOutScanner.Text() != expectedOut { | ||||||
| 		t.Fatalf("Output written to log was not what we expected\nexpected: %s\nactual:   %s", expectedOut, logScanner.Text()) | 		t.Fatalf("Output written to log was not what we expected\nexpected: %s\nactual:   %s", expectedOut, logOutScanner.Text()) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// Write a log in stderr
 | 	// Write a log in stderr
 | ||||||
|  | @ -143,8 +145,8 @@ func TestExecServer(t *testing.T) { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	expectedErr := fmt.Sprintf(pluginErr, machineName, expectedPluginErr) | 	expectedErr := fmt.Sprintf(pluginErr, machineName, expectedPluginErr) | ||||||
| 	if logScanner.Scan(); logScanner.Text() != expectedErr { | 	if logErrScanner.Scan(); logErrScanner.Text() != expectedErr { | ||||||
| 		t.Fatalf("Error written to log was not what we expected\nexpected: %s\nactual:   %s", expectedErr, logScanner.Text()) | 		t.Fatalf("Error written to log was not what we expected\nexpected: %s\nactual:   %s", expectedErr, logErrScanner.Text()) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lbp.Close() | 	lbp.Close() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue