| 
									
										
										
										
											2015-06-12 17:24:03 -07:00
										 |  |  | package file | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2015-06-12 18:18:38 -07:00
										 |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2015-06-12 17:24:03 -07:00
										 |  |  | 	"testing" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func testConfig() map[string]interface{} { | 
					
						
							|  |  |  | 	return map[string]interface{}{ | 
					
						
							| 
									
										
										
										
											2015-06-12 18:18:38 -07:00
										 |  |  | 		"source":  "src.txt", | 
					
						
							|  |  |  | 		"target":  "dst.txt", | 
					
						
							|  |  |  | 		"content": "Hello, world!", | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestContentSourceConflict(t *testing.T) { | 
					
						
							|  |  |  | 	raw := testConfig() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	_, _, errs := NewConfig(raw) | 
					
						
							|  |  |  | 	if !strings.Contains(errs.Error(), ErrContentSourceConflict.Error()) { | 
					
						
							|  |  |  | 		t.Errorf("Expected config error: %s", ErrContentSourceConflict.Error()) | 
					
						
							| 
									
										
										
										
											2015-06-12 17:24:03 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestNoFilename(t *testing.T) { | 
					
						
							|  |  |  | 	raw := testConfig() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	delete(raw, "filename") | 
					
						
							|  |  |  | 	_, _, errs := NewConfig(raw) | 
					
						
							|  |  |  | 	if errs == nil { | 
					
						
							| 
									
										
										
										
											2015-06-12 18:18:38 -07:00
										 |  |  | 		t.Errorf("Expected config error: %s", ErrTargetRequired.Error()) | 
					
						
							| 
									
										
										
										
											2015-06-12 17:24:03 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func TestNoContent(t *testing.T) { | 
					
						
							|  |  |  | 	raw := testConfig() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-12 18:18:38 -07:00
										 |  |  | 	delete(raw, "content") | 
					
						
							|  |  |  | 	delete(raw, "source") | 
					
						
							| 
									
										
										
										
											2015-06-12 17:24:03 -07:00
										 |  |  | 	_, warns, _ := NewConfig(raw) | 
					
						
							| 
									
										
										
										
											2015-06-16 11:31:53 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-12 17:24:03 -07:00
										 |  |  | 	if len(warns) == 0 { | 
					
						
							| 
									
										
										
										
											2015-06-12 18:18:38 -07:00
										 |  |  | 		t.Error("Expected config warning without any content") | 
					
						
							| 
									
										
										
										
											2015-06-12 17:24:03 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | } |