github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/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(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_bad(t *testing.T) {
    30  	c := testConfig(t, map[string]interface{}{
    31  		"source": "nope",
    32  	})
    33  	p := new(ResourceProvisioner)
    34  	warn, errs := p.Validate(c)
    35  	if len(warn) > 0 {
    36  		t.Fatalf("Warnings: %v", warn)
    37  	}
    38  	if len(errs) == 0 {
    39  		t.Fatalf("Should have errors")
    40  	}
    41  }
    42  
    43  func testConfig(
    44  	t *testing.T,
    45  	c map[string]interface{}) *terraform.ResourceConfig {
    46  	r, err := config.NewRawConfig(c)
    47  	if err != nil {
    48  		t.Fatalf("bad: %s", err)
    49  	}
    50  	return terraform.NewResourceConfig(r)
    51  }