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

     1  package functions
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  )
     8  
     9  func Test_Last(t *testing.T) {
    10  	test := []struct {
    11  		name     string
    12  		args     []interface{}
    13  		expected interface{}
    14  	}{
    15  		{
    16  			name: "last in empty string",
    17  			args: []interface{}{
    18  				"",
    19  			},
    20  			expected: "",
    21  		},
    22  		{
    23  			name: "last in string",
    24  			args: []interface{}{
    25  				"Hello",
    26  			},
    27  			expected: "o",
    28  		},
    29  		{
    30  			name: "last in empty slice",
    31  			args: []interface{}{
    32  				[]string{},
    33  			},
    34  			expected: "",
    35  		},
    36  		{
    37  			name: "last in slice",
    38  			args: []interface{}{
    39  				[]string{"Hello", "World"},
    40  			},
    41  			expected: "World",
    42  		},
    43  	}
    44  
    45  	for _, tt := range test {
    46  		t.Run(tt.name, func(t *testing.T) {
    47  			actual := Last(tt.args...)
    48  			require.Equal(t, tt.expected, actual)
    49  		})
    50  	}
    51  }