From bb8d0a5e7a024620a238f26d643dba5b25be8096 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 29 Apr 2014 00:33:35 -0700 Subject: [PATCH] provisioner/chef-solo: convert []uint8 to string --- provisioner/chef-solo/provisioner.go | 2 ++ provisioner/chef-solo/provisioner_test.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/provisioner/chef-solo/provisioner.go b/provisioner/chef-solo/provisioner.go index 8ecf8490d..1e5a47241 100644 --- a/provisioner/chef-solo/provisioner.go +++ b/provisioner/chef-solo/provisioner.go @@ -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 { diff --git a/provisioner/chef-solo/provisioner_test.go b/provisioner/chef-solo/provisioner_test.go index 35fdb915a..73e54de57 100644 --- a/provisioner/chef-solo/provisioner_test.go +++ b/provisioner/chef-solo/provisioner_test.go @@ -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"]) + } }