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

     1  package functions
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_Take(t *testing.T) {
    10  	tests := []struct {
    11  		name     string
    12  		args     []interface{}
    13  		expected interface{}
    14  	}{
    15  		{
    16  			name: "take a string",
    17  			args: []interface{}{
    18  				"hello",
    19  				2,
    20  			},
    21  			expected: "he",
    22  		},
    23  		{
    24  			name: "take a string with invalid count",
    25  			args: []interface{}{
    26  				"hello",
    27  				10,
    28  			},
    29  			expected: "hello",
    30  		},
    31  		{
    32  			name: "take a string from slice",
    33  			args: []interface{}{
    34  				[]string{"a", "b", "c"},
    35  				2,
    36  			},
    37  			expected: []string{"a", "b"},
    38  		},
    39  		{
    40  			name: "take a string from a slice",
    41  			args: []interface{}{
    42  				[]string{"a", "b", "c"},
    43  				2,
    44  			},
    45  			expected: []string{"a", "b"},
    46  		},
    47  		{
    48  			name: "take a string from a slice with invalid count",
    49  			args: []interface{}{
    50  				[]string{"a", "b", "c"},
    51  				10,
    52  			},
    53  			expected: []string{"a", "b", "c"},
    54  		},
    55  	}
    56  
    57  	for _, tt := range tests {
    58  		t.Run(tt.name, func(t *testing.T) {
    59  			actual := Take(tt.args...)
    60  			assert.Equal(t, tt.expected, actual)
    61  		})
    62  	}
    63  }