github.com/blend/go-sdk@v1.20220411.3/validate/many_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package validate
     9  
    10  import (
    11  	"testing"
    12  
    13  	"github.com/blend/go-sdk/assert"
    14  )
    15  
    16  type manyTest struct {
    17  	Foo *string
    18  	Bar *string
    19  	Baz *string
    20  }
    21  
    22  func TestManyNil(t *testing.T) {
    23  	assert := assert.New(t)
    24  
    25  	refStr := func(val string) *string { return &val }
    26  
    27  	bad := manyTest{
    28  		Foo: refStr("foo"),
    29  		Bar: refStr("bar"),
    30  		Baz: refStr("baz"),
    31  	}
    32  	assert.NotNil(Many(bad.Foo, bad.Bar, bad.Baz).Nil()())
    33  
    34  	maybe := manyTest{
    35  		Bar: refStr("bar"),
    36  	}
    37  	assert.NotNil(Many(maybe.Foo, maybe.Bar, maybe.Baz).Nil()())
    38  
    39  	good := manyTest{}
    40  	assert.Nil(Many(good.Foo, good.Bar, good.Baz).Nil()())
    41  }
    42  
    43  func TestManyNotNil(t *testing.T) {
    44  	assert := assert.New(t)
    45  
    46  	refStr := func(val string) *string { return &val }
    47  
    48  	bad := manyTest{}
    49  	assert.NotNil(Many(bad.Foo, bad.Bar, bad.Baz).NotNil()())
    50  
    51  	maybe := manyTest{
    52  		Bar: refStr("bar"),
    53  	}
    54  	assert.Nil(Many(maybe.Foo, maybe.Bar, maybe.Baz).NotNil()())
    55  
    56  	good := manyTest{
    57  		Foo: refStr("foo"),
    58  		Bar: refStr("bar"),
    59  		Baz: refStr("baz"),
    60  	}
    61  	assert.Nil(Many(good.Foo, good.Bar, good.Baz).NotNil()())
    62  }
    63  
    64  func TestManyOneNotNil(t *testing.T) {
    65  	assert := assert.New(t)
    66  
    67  	refStr := func(val string) *string { return &val }
    68  
    69  	bad := manyTest{}
    70  	assert.NotNil(Many(bad.Foo, bad.Bar, bad.Baz).OneNotNil()())
    71  
    72  	maybe := manyTest{
    73  		Bar: refStr("bar"),
    74  	}
    75  	assert.Nil(Many(maybe.Foo, maybe.Bar, maybe.Baz).OneNotNil()())
    76  
    77  	good := manyTest{
    78  		Foo: refStr("foo"),
    79  		Bar: refStr("bar"),
    80  		Baz: refStr("baz"),
    81  	}
    82  	assert.NotNil(Many(good.Foo, good.Bar, good.Baz).OneNotNil()())
    83  }