github.com/wtfutil/wtf@v0.43.0/cfg/validations_test.go (about)

     1  package cfg
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  var (
    10  	vals = NewValidations()
    11  )
    12  
    13  func Test_intValueFor(t *testing.T) {
    14  	vals.append("left", newPositionValidation("left", 3, nil))
    15  
    16  	tests := []struct {
    17  		name     string
    18  		key      string
    19  		expected int
    20  	}{
    21  		{
    22  			name:     "with valid key",
    23  			key:      "left",
    24  			expected: 3,
    25  		},
    26  		{
    27  			name:     "with invalid key",
    28  			key:      "cat",
    29  			expected: 0,
    30  		},
    31  	}
    32  
    33  	for _, tt := range tests {
    34  		t.Run(tt.name, func(t *testing.T) {
    35  			assert.Equal(t, tt.expected, vals.intValueFor(tt.key))
    36  		})
    37  	}
    38  }