github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/provisioners/file/resource_provisioner_test.go (about) 1 package file 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/terraform/config" 7 "github.com/hashicorp/terraform/terraform" 8 ) 9 10 func TestResourceProvider_Validate_good_source(t *testing.T) { 11 c := testConfig(t, map[string]interface{}{ 12 "source": "/tmp/foo", 13 "destination": "/tmp/bar", 14 }) 15 p := Provisioner() 16 warn, errs := p.Validate(c) 17 if len(warn) > 0 { 18 t.Fatalf("Warnings: %v", warn) 19 } 20 if len(errs) > 0 { 21 t.Fatalf("Errors: %v", errs) 22 } 23 } 24 25 func TestResourceProvider_Validate_good_content(t *testing.T) { 26 c := testConfig(t, map[string]interface{}{ 27 "content": "value to copy", 28 "destination": "/tmp/bar", 29 }) 30 p := Provisioner() 31 warn, errs := p.Validate(c) 32 if len(warn) > 0 { 33 t.Fatalf("Warnings: %v", warn) 34 } 35 if len(errs) > 0 { 36 t.Fatalf("Errors: %v", errs) 37 } 38 } 39 40 func TestResourceProvider_Validate_bad_not_destination(t *testing.T) { 41 c := testConfig(t, map[string]interface{}{ 42 "source": "nope", 43 }) 44 p := Provisioner() 45 warn, errs := p.Validate(c) 46 if len(warn) > 0 { 47 t.Fatalf("Warnings: %v", warn) 48 } 49 if len(errs) == 0 { 50 t.Fatalf("Should have errors") 51 } 52 } 53 54 func TestResourceProvider_Validate_bad_to_many_src(t *testing.T) { 55 c := testConfig(t, map[string]interface{}{ 56 "source": "nope", 57 "content": "value to copy", 58 "destination": "/tmp/bar", 59 }) 60 p := Provisioner() 61 warn, errs := p.Validate(c) 62 if len(warn) > 0 { 63 t.Fatalf("Warnings: %v", warn) 64 } 65 if len(errs) == 0 { 66 t.Fatalf("Should have errors") 67 } 68 } 69 70 func testConfig( 71 t *testing.T, 72 c map[string]interface{}) *terraform.ResourceConfig { 73 r, err := config.NewRawConfig(c) 74 if err != nil { 75 t.Fatalf("bad: %s", err) 76 } 77 return terraform.NewResourceConfig(r) 78 }