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

     1  package functions
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_CreateObject(t *testing.T) {
    10  
    11  	tests := []struct {
    12  		name     string
    13  		args     []interface{}
    14  		expected interface{}
    15  	}{
    16  		{
    17  			name:     "CreateObject with no args",
    18  			args:     []interface{}{},
    19  			expected: map[string]interface{}{},
    20  		},
    21  		{
    22  			name:     "CreateObject with one arg",
    23  			args:     []interface{}{"foo", "bar"},
    24  			expected: map[string]interface{}{"foo": "bar"},
    25  		},
    26  		{
    27  			name:     "CreateObject with two args",
    28  			args:     []interface{}{"foo", "bar", "baz", "qux"},
    29  			expected: map[string]interface{}{"foo": "bar", "baz": "qux"},
    30  		},
    31  		{
    32  			name:     "CreateObject with three args",
    33  			args:     []interface{}{"foo", "bar", "baz", 1, "quux", true},
    34  			expected: map[string]interface{}{"foo": "bar", "baz": 1, "quux": true},
    35  		},
    36  		{
    37  			name:     "CreateObject with odd number of args",
    38  			args:     []interface{}{"foo", "bar", "baz"},
    39  			expected: map[string]interface{}{},
    40  		},
    41  		{
    42  			name: "CreateObject with odd number of args",
    43  			args: []interface{}{"foo", "bar", "baz", []string{"Hello", "World"}},
    44  			expected: map[string]interface{}{
    45  				"foo": "bar",
    46  				"baz": []string{
    47  					"Hello", "World",
    48  				},
    49  			},
    50  		},
    51  	}
    52  
    53  	for _, tt := range tests {
    54  		t.Run(tt.name, func(t *testing.T) {
    55  			got := CreateObject(tt.args...)
    56  			assert.Equal(t, tt.expected, got)
    57  		})
    58  	}
    59  
    60  }