github.com/khulnasoft-lab/defsec@v1.0.5-0.20230827010352-5e9f46893d95/pkg/scanners/azure/functions/json_test.go (about)

     1  package functions
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_JSON(t *testing.T) {
    10  
    11  	tests := []struct {
    12  		name     string
    13  		args     []interface{}
    14  		expected map[string]interface{}
    15  	}{
    16  		{
    17  			name: "simple json string to json type",
    18  			args: []interface{}{
    19  				`{"hello": "world"}`,
    20  			},
    21  			expected: map[string]interface{}{
    22  				"hello": "world",
    23  			},
    24  		},
    25  		{
    26  			name: "more complex json string to json type",
    27  			args: []interface{}{
    28  				`{"hello": ["world", "world2"]}`,
    29  			},
    30  			expected: map[string]interface{}{
    31  				"hello": []interface{}{"world", "world2"},
    32  			},
    33  		},
    34  	}
    35  
    36  	for _, tt := range tests {
    37  		t.Run(tt.name, func(t *testing.T) {
    38  			actual := JSON(tt.args...)
    39  			assert.Equal(t, tt.expected, actual)
    40  		})
    41  	}
    42  }