github.com/GoogleCloudPlatform/terraformer@v0.8.18/terraformutils/flatmap_test.go (about)

     1  package terraformutils
     2  
     3  import (
     4  	"regexp"
     5  	"testing"
     6  
     7  	"github.com/zclconf/go-cty/cty"
     8  )
     9  
    10  func TestNestedAttributeFiltering(t *testing.T) {
    11  	attributes := map[string]string{
    12  		"attribute":        "value1",
    13  		"nested.attribute": "value2",
    14  	}
    15  
    16  	ignoreKeys := []*regexp.Regexp{
    17  		regexp.MustCompile(`^attribute$`),
    18  	}
    19  	parser := NewFlatmapParser(attributes, ignoreKeys, []*regexp.Regexp{})
    20  
    21  	attributesType := cty.Object(map[string]cty.Type{
    22  		"attribute": cty.String,
    23  		"nested": cty.Object(map[string]cty.Type{
    24  			"attribute": cty.String,
    25  		}),
    26  	})
    27  
    28  	result, _ := parser.Parse(attributesType)
    29  
    30  	if _, ok := result["attribute"]; ok {
    31  		t.Errorf("failed to resolve %v", result)
    32  	}
    33  	if val, ok := result["nested"].(map[string]interface{})["attribute"]; !ok && val != "value2" {
    34  		t.Errorf("failed to resolve %v", result)
    35  	}
    36  }