provisioner/chef-solo: convert []uint8 to string

This commit is contained in:
Mitchell Hashimoto 2014-04-29 00:33:35 -07:00
parent 25638c3e04
commit bb8d0a5e7a
2 changed files with 12 additions and 1 deletions

View File

@ -499,6 +499,8 @@ func (p *Provisioner) deepJsonFix(key string, current interface{}) (interface{},
}
return val, nil
case []uint8:
return string(c), nil
case map[interface{}]interface{}:
val := make(map[string]interface{})
for k, v := range c {

View File

@ -267,7 +267,7 @@ func TestProvisionerPrepare_jsonNested(t *testing.T) {
config := testConfig()
config["json"] = map[string]interface{}{
"foo": map[interface{}]interface{}{
"bar": "baz",
"bar": []uint8("baz"),
},
"bar": []interface{}{
@ -281,6 +281,7 @@ func TestProvisionerPrepare_jsonNested(t *testing.T) {
"bFalse": false,
"bTrue": true,
"bNil": nil,
"bStr": []uint8("bar"),
"bInt": 1,
"bFloat": 4.5,
@ -291,4 +292,12 @@ func TestProvisionerPrepare_jsonNested(t *testing.T) {
if err != nil {
t.Fatalf("err: %s", err)
}
fooMap := p.config.Json["foo"].(map[string]interface{})
if fooMap["bar"] != "baz" {
t.Fatalf("nope: %#v", fooMap["bar"])
}
if p.config.Json["bStr"] != "bar" {
t.Fatalf("nope: %#v", fooMap["bar"])
}
}