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

     1  package functions
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_IndexOf(t *testing.T) {
    10  
    11  	tests := []struct {
    12  		name     string
    13  		args     []interface{}
    14  		expected int
    15  	}{
    16  		{
    17  			name: "get index of string that is there",
    18  			args: []interface{}{
    19  				"Hello world!",
    20  				"Hell",
    21  			},
    22  			expected: 0,
    23  		},
    24  		{
    25  			name: "get index of string that is there as well",
    26  			args: []interface{}{
    27  				"Hello world!",
    28  				"world",
    29  			},
    30  			expected: 6,
    31  		},
    32  		{
    33  			name: "get index of string that isn't there",
    34  			args: []interface{}{
    35  				"Hello world!",
    36  				"planet!",
    37  			},
    38  			expected: -1,
    39  		},
    40  	}
    41  
    42  	for _, tt := range tests {
    43  		t.Run(tt.name, func(t *testing.T) {
    44  			actual := IndexOf(tt.args...)
    45  			assert.Equal(t, tt.expected, actual)
    46  		})
    47  	}
    48  }