Merge pull request #13607 from vieux/PrintfIfNotEmpty
do not print empty values in docker info
This commit is contained in:
		
						commit
						cf18f70f12
					
				
					 2 changed files with 31 additions and 0 deletions
				
			
		
							
								
								
									
										14
									
								
								ioutils/fmt.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								ioutils/fmt.go
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,14 @@ | |||
| package ioutils | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| ) | ||||
| 
 | ||||
| // FprintfIfNotEmpty prints the string value if it's not empty | ||||
| func FprintfIfNotEmpty(w io.Writer, format, value string) (int, error) { | ||||
| 	if value != "" { | ||||
| 		return fmt.Fprintf(w, format, value) | ||||
| 	} | ||||
| 	return 0, nil | ||||
| } | ||||
							
								
								
									
										17
									
								
								ioutils/fmt_test.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								ioutils/fmt_test.go
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,17 @@ | |||
| package ioutils | ||||
| 
 | ||||
| import "testing" | ||||
| 
 | ||||
| func TestFprintfIfNotEmpty(t *testing.T) { | ||||
| 	wc := NewWriteCounter(&NopWriter{}) | ||||
| 	n, _ := FprintfIfNotEmpty(wc, "foo%s", "") | ||||
| 
 | ||||
| 	if wc.Count != 0 || n != 0 { | ||||
| 		t.Errorf("Wrong count: %v vs. %v vs. 0", wc.Count, n) | ||||
| 	} | ||||
| 
 | ||||
| 	n, _ = FprintfIfNotEmpty(wc, "foo%s", "bar") | ||||
| 	if wc.Count != 6 || n != 6 { | ||||
| 		t.Errorf("Wrong count: %v vs. %v vs. 6", wc.Count, n) | ||||
| 	} | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue