github.com/yandex/pandora@v0.5.32/components/providers/scenario/vs/vs_variables_test.go (about)

     1  package vs
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestVariableSourceVariables_Init(t *testing.T) {
    10  	tests := []struct {
    11  		name      string
    12  		variables map[string]any
    13  		want      map[string]any
    14  		wantErr   assert.ErrorAssertionFunc
    15  	}{
    16  		{
    17  			name: "default",
    18  			variables: map[string]any{
    19  				"random": "randInt(0,1)",
    20  				"object": map[string]any{
    21  					"strings": []string{
    22  						"randString(2, a)",
    23  						"randString(3, b)",
    24  					},
    25  				},
    26  			},
    27  			want: map[string]any{
    28  				"random": "0",
    29  				"object": map[string]any{
    30  					"strings": []string{
    31  						"aa",
    32  						"bbb",
    33  					},
    34  				},
    35  			},
    36  			wantErr: assert.NoError,
    37  		},
    38  		{
    39  			name: "invalid func name return string",
    40  			variables: map[string]any{
    41  				"random": "randInteger(0,1)",
    42  			},
    43  			want: map[string]any{
    44  				"random": "randInteger(0,1)",
    45  			},
    46  			wantErr: assert.NoError,
    47  		},
    48  		{
    49  			name: "invalid func arg",
    50  			variables: map[string]any{
    51  				"random": "randInt(asdf)",
    52  			},
    53  			want: map[string]any{
    54  				"random": "",
    55  			},
    56  			wantErr: assert.Error,
    57  		},
    58  	}
    59  	for _, tt := range tests {
    60  		t.Run(tt.name, func(t *testing.T) {
    61  			v := &VariableSourceVariables{Variables: tt.variables}
    62  			err := v.Init()
    63  			if tt.wantErr(t, err) {
    64  				assert.Equal(t, tt.want, v.Variables)
    65  			}
    66  		})
    67  	}
    68  }