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

     1  package functions
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_Length(t *testing.T) {
    10  
    11  	tests := []struct {
    12  		name     string
    13  		args     []interface{}
    14  		expected int
    15  	}{
    16  		{
    17  			name: "length of a string",
    18  			args: []interface{}{
    19  				"hello",
    20  			},
    21  			expected: 5,
    22  		},
    23  		{
    24  			name: "length of an empty string",
    25  			args: []interface{}{
    26  				"",
    27  			},
    28  			expected: 0,
    29  		},
    30  		{
    31  			name: "length of an empty slice",
    32  			args: []interface{}{
    33  				[]string{},
    34  			},
    35  			expected: 0,
    36  		},
    37  		{
    38  			name: "length of an slice with items",
    39  			args: []interface{}{
    40  				[]string{
    41  					"hello", "world",
    42  				},
    43  			},
    44  			expected: 2,
    45  		},
    46  	}
    47  	for _, tt := range tests {
    48  		t.Run(tt.name, func(t *testing.T) {
    49  			actual := Length(tt.args...)
    50  			assert.Equal(t, tt.expected, actual)
    51  		})
    52  	}
    53  }