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

     1  package functions
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func Test_PadLeft(t *testing.T) {
    10  
    11  	tests := []struct {
    12  		name     string
    13  		args     []interface{}
    14  		expected string
    15  	}{
    16  		{
    17  			name: "pad left with a input smaller than length",
    18  			args: []interface{}{
    19  				"1234",
    20  				8,
    21  				"0",
    22  			},
    23  			expected: "00001234",
    24  		},
    25  		{
    26  			name: "pad left with a input larger than length",
    27  			args: []interface{}{
    28  				"1234",
    29  				2,
    30  				"0",
    31  			},
    32  			expected: "1234",
    33  		},
    34  		{
    35  			name: "pad left with a input same as than length",
    36  			args: []interface{}{
    37  				"1234",
    38  				4,
    39  				"0",
    40  			},
    41  			expected: "1234",
    42  		},
    43  		{
    44  			name: "pad left with larger padding character",
    45  			args: []interface{}{
    46  				"1234",
    47  				8,
    48  				"00",
    49  			},
    50  			expected: "00001234",
    51  		},
    52  	}
    53  
    54  	for _, tt := range tests {
    55  		t.Run(tt.name, func(t *testing.T) {
    56  			actual := PadLeft(tt.args...)
    57  			assert.Equal(t, tt.expected, actual)
    58  		})
    59  	}
    60  
    61  }