github.com/jerryclinesmith/packer@v0.3.7/provisioner/chef-solo/provisioner_test.go (about)

     1  package chefsolo
     2  
     3  import (
     4  	"github.com/mitchellh/packer/packer"
     5  	"io/ioutil"
     6  	"os"
     7  	"testing"
     8  )
     9  
    10  func testConfig() map[string]interface{} {
    11  	return map[string]interface{}{}
    12  }
    13  
    14  func TestProvisioner_Impl(t *testing.T) {
    15  	var raw interface{}
    16  	raw = &Provisioner{}
    17  	if _, ok := raw.(packer.Provisioner); !ok {
    18  		t.Fatalf("must be a Provisioner")
    19  	}
    20  }
    21  
    22  func TestProvisionerPrepare_cookbookPaths(t *testing.T) {
    23  	var p Provisioner
    24  
    25  	path1, err := ioutil.TempDir("", "cookbooks_one")
    26  	if err != nil {
    27  		t.Fatalf("err: %s", err)
    28  	}
    29  
    30  	path2, err := ioutil.TempDir("", "cookbooks_two")
    31  	if err != nil {
    32  		t.Fatalf("err: %s", err)
    33  	}
    34  
    35  	defer os.Remove(path1)
    36  	defer os.Remove(path2)
    37  
    38  	config := testConfig()
    39  	config["cookbook_paths"] = []string{path1, path2}
    40  
    41  	err = p.Prepare(config)
    42  	if err != nil {
    43  		t.Fatalf("err: %s", err)
    44  	}
    45  
    46  	if len(p.config.CookbookPaths) != 2 {
    47  		t.Fatalf("unexpected: %#v", p.config.CookbookPaths)
    48  	}
    49  
    50  	if p.config.CookbookPaths[0] != path1 || p.config.CookbookPaths[1] != path2 {
    51  		t.Fatalf("unexpected: %#v", p.config.CookbookPaths)
    52  	}
    53  }
    54  
    55  func TestProvisionerPrepare_json(t *testing.T) {
    56  	config := testConfig()
    57  	config["json"] = map[string]interface{}{
    58  		"foo": "{{ user `foo` }}",
    59  	}
    60  
    61  	config[packer.UserVariablesConfigKey] = map[string]string{
    62  		"foo": `"bar\baz"`,
    63  	}
    64  
    65  	var p Provisioner
    66  	err := p.Prepare(config)
    67  	if err != nil {
    68  		t.Fatalf("err: %s", err)
    69  	}
    70  
    71  	if p.config.Json["foo"] != `"bar\baz"` {
    72  		t.Fatalf("bad: %#v", p.config.Json)
    73  	}
    74  }