| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | package test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"io/ioutil" | 
					
						
							|  |  |  | 	"os" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TempFile will create a temporary file on disk and returns the name and a cleanup function to remove it later. | 
					
						
							| 
									
										
										
										
											2016-10-02 15:58:01 +01:00
										 |  |  | func TempFile(dir, content string) (string, func(), error) { | 
					
						
							| 
									
										
										
										
											2016-08-19 17:14:17 -07:00
										 |  |  | 	f, err := ioutil.TempFile(dir, "go-test-tmpfile") | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							|  |  |  | 		return "", nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if err := ioutil.WriteFile(f.Name(), []byte(content), 0644); err != nil { | 
					
						
							|  |  |  | 		return "", nil, err | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	rmFunc := func() { os.Remove(f.Name()) } | 
					
						
							|  |  |  | 	return f.Name(), rmFunc, nil | 
					
						
							|  |  |  | } |