github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/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 TestResourceProvisioner_impl(t *testing.T) { 11 var _ terraform.ResourceProvisioner = new(ResourceProvisioner) 12 } 13 14 func TestResourceProvider_Validate_good_source(t *testing.T) { 15 c := testConfig(t, map[string]interface{}{ 16 "source": "/tmp/foo", 17 "destination": "/tmp/bar", 18 }) 19 p := new(ResourceProvisioner) 20 warn, errs := p.Validate(c) 21 if len(warn) > 0 { 22 t.Fatalf("Warnings: %v", warn) 23 } 24 if len(errs) > 0 { 25 t.Fatalf("Errors: %v", errs) 26 } 27 } 28 29 func TestResourceProvider_Validate_good_content(t *testing.T) { 30 c := testConfig(t, map[string]interface{}{ 31 "content": "value to copy", 32 "destination": "/tmp/bar", 33 }) 34 p := new(ResourceProvisioner) 35 warn, errs := p.Validate(c) 36 if len(warn) > 0 { 37 t.Fatalf("Warnings: %v", warn) 38 } 39 if len(errs) > 0 { 40 t.Fatalf("Errors: %v", errs) 41 } 42 } 43 44 func TestResourceProvider_Validate_bad_not_destination(t *testing.T) { 45 c := testConfig(t, map[string]interface{}{ 46 "source": "nope", 47 }) 48 p := new(ResourceProvisioner) 49 warn, errs := p.Validate(c) 50 if len(warn) > 0 { 51 t.Fatalf("Warnings: %v", warn) 52 } 53 if len(errs) == 0 { 54 t.Fatalf("Should have errors") 55 } 56 } 57 58 func TestResourceProvider_Validate_bad_to_many_src(t *testing.T) { 59 c := testConfig(t, map[string]interface{}{ 60 "source": "nope", 61 "content": "value to copy", 62 "destination": "/tmp/bar", 63 }) 64 p := new(ResourceProvisioner) 65 warn, errs := p.Validate(c) 66 if len(warn) > 0 { 67 t.Fatalf("Warnings: %v", warn) 68 } 69 if len(errs) == 0 { 70 t.Fatalf("Should have errors") 71 } 72 } 73 74 func testConfig( 75 t *testing.T, 76 c map[string]interface{}) *terraform.ResourceConfig { 77 r, err := config.NewRawConfig(c) 78 if err != nil { 79 t.Fatalf("bad: %s", err) 80 } 81 return terraform.NewResourceConfig(r) 82 }