clean up and retab.

This commit is contained in:
Matthew Hooker 2013-08-28 17:35:43 -07:00
parent e21e980647
commit fc595de0fd
2 changed files with 14 additions and 16 deletions

View File

@ -56,27 +56,27 @@ func TestJsonTemplateProcess_user(t *testing.T) {
tpl.UserVars["foo"] = "bar"
jsonData := make(map[string]interface{})
jsonData["key"] = map[string]string{
"key1": "{{user `foo`}}",
}
jsonData["key"] = map[string]string{
"key1": "{{user `foo`}}",
}
jsonBytes, err := json.MarshalIndent(jsonData, "", " ")
if err != nil {
t.Fatalf("err: %s", err)
t.Fatalf("err: %s", err)
}
var jsonString = string(jsonBytes)
var jsonString = string(jsonBytes)
result, err := tpl.Process(jsonString, nil)
result, err := tpl.Process(jsonString, nil)
if err != nil {
t.Fatalf("err: %s", err)
}
var dat map[string]map[string]interface{}
if err := json.Unmarshal([]byte(result), &dat); err != nil {
var dat map[string]map[string]interface{}
if err := json.Unmarshal([]byte(result), &dat); err != nil {
t.Fatalf("err: %s", err)
}
}
if dat["key"]["key1"] != "bar" {
t.Fatalf("found %s instead", dat["key"]["key1"])
}
if dat["key"]["key1"] != "bar" {
t.Fatalf("found %s instead", dat["key"]["key1"])
}
}

View File

@ -235,17 +235,15 @@ func (p *Provisioner) createJson(ui packer.Ui, comm packer.Communicator) (string
if err != nil {
return "", err
}
var jsonString = string(jsonBytes)
println(jsonString)
result, err := p.config.tpl.Process(jsonString, nil)
jsonBytesProcessed, err := p.config.tpl.Process(string(jsonBytes), nil)
if err != nil {
return "", err
}
// Upload the bytes
remotePath := filepath.Join(p.config.StagingDir, "node.json")
if err := comm.Upload(remotePath, bytes.NewReader([]byte(result))); err != nil {
if err := comm.Upload(remotePath, bytes.NewReader([]byte(jsonBytesProcessed))); err != nil {
return "", err
}