github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/rego/convert/slice_test.go (about)

     1  package convert
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  
     7  	"github.com/khulnasoft-lab/defsec/pkg/types"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  )
    11  
    12  func Test_SliceConversion(t *testing.T) {
    13  	input := []struct {
    14  		X string
    15  		Y int
    16  		Z struct {
    17  			A float64
    18  		}
    19  	}{
    20  		{},
    21  	}
    22  	input[0].Z.A = 123
    23  	converted := SliceToRego(reflect.ValueOf(input))
    24  	assert.Equal(t, []interface{}{map[string]interface{}{"z": map[string]interface{}{}}}, converted)
    25  }
    26  
    27  func Test_SliceTypesConversion(t *testing.T) {
    28  	input := []types.StringValue{
    29  		types.String("test1", types.NewTestMetadata()),
    30  		types.String("test2", types.NewTestMetadata()),
    31  	}
    32  	converted := SliceToRego(reflect.ValueOf(input))
    33  	assert.Equal(t, []interface{}{
    34  		map[string]interface{}{
    35  			"value":        "test1",
    36  			"filepath":     "test.test",
    37  			"startline":    123,
    38  			"endline":      123,
    39  			"sourceprefix": "",
    40  			"managed":      true,
    41  			"explicit":     false,
    42  			"fskey":        "",
    43  			"resource":     "",
    44  		},
    45  		map[string]interface{}{
    46  			"value":        "test2",
    47  			"filepath":     "test.test",
    48  			"startline":    123,
    49  			"endline":      123,
    50  			"sourceprefix": "",
    51  			"managed":      true,
    52  			"explicit":     false,
    53  			"fskey":        "",
    54  			"resource":     "",
    55  		},
    56  	}, converted)
    57  }