github.phpd.cn/hashicorp/packer@v1.3.2/builder/file/config_test.go (about) 1 package file 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func testConfig() map[string]interface{} { 9 return map[string]interface{}{ 10 "source": "src.txt", 11 "target": "dst.txt", 12 "content": "Hello, world!", 13 } 14 } 15 16 func TestContentSourceConflict(t *testing.T) { 17 raw := testConfig() 18 19 _, _, errs := NewConfig(raw) 20 if !strings.Contains(errs.Error(), ErrContentSourceConflict.Error()) { 21 t.Errorf("Expected config error: %s", ErrContentSourceConflict.Error()) 22 } 23 } 24 25 func TestNoFilename(t *testing.T) { 26 raw := testConfig() 27 28 delete(raw, "filename") 29 _, _, errs := NewConfig(raw) 30 if errs == nil { 31 t.Errorf("Expected config error: %s", ErrTargetRequired.Error()) 32 } 33 } 34 35 func TestNoContent(t *testing.T) { 36 raw := testConfig() 37 38 delete(raw, "content") 39 delete(raw, "source") 40 _, warns, _ := NewConfig(raw) 41 42 if len(warns) == 0 { 43 t.Error("Expected config warning without any content") 44 } 45 }