func TestFixHCL(t *testing.T) { var vHCL interface{} if err := hcl.Unmarshal(stackfixture.StackHCL, &vHCL); err != nil { t.Fatalf("hcl.Unmarshal()=%s", err) } if testing.Verbose() { t.Logf("original (vHCL):\n%s", mustJSON(vHCL)) } if reflect.DeepEqual(vHCL, stackfixture.Stack) { t.Fatal("expected HCL-encoded stack to not unmarshal cleanly") } stack.FixHCL(vHCL) if !reflect.DeepEqual(vHCL, stackfixture.Stack) { t.Fatalf("got %+v, want %+v", vHCL, stackfixture.Stack) } var vJSON interface{} if err := json.Unmarshal(stackfixture.StackJSON, &vJSON); err != nil { t.Fatalf("json.Unmarshal()=%s", err) } if testing.Verbose() { t.Logf("fixed (vJSON):\n%s", mustJSON(vJSON)) } if !reflect.DeepEqual(vJSON, vHCL) { t.Fatalf("got %+v, want %+v", vJSON, vHCL) } }
func (c *Client) jsonReencode(data []byte) ([]byte, error) { var jsonv interface{} if err := json.Unmarshal(data, &jsonv); err == nil { return jsonMarshal(jsonv) } var hclv interface{} if err := hcl.Unmarshal(data, &hclv); err == nil { fixHCL(hclv) return jsonMarshal(hclv) } var ymlv interface{} if err := yaml.Unmarshal(data, &ymlv); err == nil { return jsonMarshal(fixYAML(ymlv)) } return nil, errors.New("unknown encoding") }