github.com/GoogleCloudPlatform/terraformer@v0.8.18/terraformutils/hcl_test.go (about) 1 // Copyright 2020 The Terraformer Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package terraformutils 16 17 import ( 18 "strings" 19 "testing" 20 ) 21 22 func TestPrintResource(t *testing.T) { 23 var resources []Resource 24 var nested []map[string]interface{} 25 nested = append(nested, mapI("field1", "egg")) 26 importResource := prepare("ID1", "type1", map[string]string{ 27 "type1": "ID2", 28 "map1.%": "1", 29 "map1.foo": "bar", 30 "nested.#": "1", 31 "nested.0.map1.#": "1", 32 "nested.0.map1.0.field1": "egg", 33 "nested2.#": "1", 34 "nested2.0.field1": "spam", 35 "nested2.0.map2.%": "1", 36 "nested2.0.map2.foo": "bar", 37 }, map[string]interface{}{ 38 "type1": "ID2", 39 "map1": mapI("foo", "bar"), 40 "nested": mapI("map1", nested), 41 "nested2": map[string]interface{}{"map2": mapI("bar", "foo"), "field1": "egg"}, 42 }) 43 resources = append(resources, importResource) 44 providerData := map[string]interface{}{} 45 output := "hcl" 46 data, _ := HclPrintResource(resources, providerData, output) 47 48 if strings.Count(string(data), "map1 = ") != 1 { 49 t.Errorf("failed to parse data %s", string(data)) 50 } 51 if strings.Count(string(data), "map2 = ") != 1 { 52 t.Errorf("failed to parse data %s", string(data)) 53 } 54 }