1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| package builder import ( "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestResourcePoolConfigBuilder_Build(t *testing.T) { tests := []struct { name string builder *ResourcePoolConfigBuilder want *ResourcePoolConfig wantErr bool }{ { name: "name empty", builder: &ResourcePoolConfigBuilder{ name: "", maxTotal: 0, }, want: nil, wantErr: true, }, { name: "maxIdle < minIdle", builder: &ResourcePoolConfigBuilder{ name: "test", maxTotal: 0, maxIdle: 10, minIdle: 20, }, want: nil, wantErr: true, }, { name: "success", builder: &ResourcePoolConfigBuilder{ name: "test", }, want: &ResourcePoolConfig{ name: "test", maxTotal: defaultMaxTotal, maxIdle: defaultMaxIdle, minIdle: defaultMinIdle, }, wantErr: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got, err := tt.builder.Build() require.Equalf(t, tt.wantErr, err != nil, "Build() error = %v, wantErr %v", err, tt.wantErr) assert.Equal(t, tt.want, got) }) } }
|