github.com/blend/go-sdk@v1.20220411.3/validate/uint64_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 func TestUint64Min(t *testing.T) { 17 assert := assert.New(t) 18 19 var verr error 20 var val uint64 = 10 21 verr = Uint64(&val).Min(1)() 22 assert.Nil(verr) 23 24 val = 10 25 verr = Uint64(&val).Min(10)() 26 assert.Nil(verr) 27 28 verr = Uint64(nil).Min(10)() 29 assert.NotNil(verr) 30 assert.Nil(ErrValue(verr)) 31 assert.Equal(ErrUint64Min, ErrCause(verr)) 32 33 val = 1 34 verr = Uint64(&val).Min(10)() 35 assert.NotNil(verr) 36 assert.NotNil(ErrValue(verr)) 37 assert.Equal(ErrUint64Min, ErrCause(verr)) 38 39 val = 10 40 verr = Uint64(&val).Min(10)() 41 assert.Nil(verr) 42 } 43 44 func TestUint64Max(t *testing.T) { 45 assert := assert.New(t) 46 47 var verr error 48 var val uint64 = 1 49 verr = Uint64(&val).Max(10)() 50 assert.Nil(verr) 51 52 verr = Uint64(nil).Max(10)() 53 assert.Nil(verr) 54 55 val = 10 56 verr = Uint64(&val).Max(10)() 57 assert.Nil(verr) 58 59 val = 11 60 verr = Uint64(&val).Max(10)() 61 assert.NotNil(verr) 62 assert.NotNil(ErrValue(verr)) 63 assert.Equal(ErrUint64Max, ErrCause(verr)) 64 } 65 66 func TestUint64Between(t *testing.T) { 67 assert := assert.New(t) 68 69 var verr error 70 var val uint64 = 5 71 verr = Uint64(&val).Between(1, 10)() 72 assert.Nil(verr) 73 74 verr = Uint64(nil).Between(5, 10)() 75 assert.NotNil(verr) 76 assert.Nil(ErrValue(verr)) 77 assert.Equal(ErrUint64Min, ErrCause(verr)) 78 79 val = 1 80 verr = Uint64(&val).Between(5, 10)() 81 assert.NotNil(verr) 82 assert.Equal(1, ErrValue(verr)) 83 assert.Equal(ErrUint64Min, ErrCause(verr)) 84 85 val = 5 86 verr = Uint64(&val).Between(5, 10)() 87 assert.Nil(verr) 88 89 val = 10 90 verr = Uint64(&val).Between(5, 10)() 91 assert.Nil(verr) 92 93 val = 11 94 verr = Uint64(&val).Between(5, 10)() 95 assert.NotNil(verr) 96 assert.Equal(11, ErrValue(verr)) 97 assert.Equal(ErrUint64Max, ErrCause(verr)) 98 } 99 100 func TestUint64Zero(t *testing.T) { 101 assert := assert.New(t) 102 103 var verr error 104 var val uint64 = 0 105 verr = Uint64(&val).Zero()() 106 assert.Nil(verr) 107 108 verr = Uint64(nil).Zero()() 109 assert.NotNil(verr) 110 assert.Nil(ErrValue(verr)) 111 assert.Equal(ErrUint64Zero, ErrCause(verr)) 112 113 val = 5 114 verr = Uint64(&val).Zero()() 115 assert.NotNil(verr) 116 assert.NotNil(ErrValue(verr)) 117 assert.Equal(ErrUint64Zero, ErrCause(verr)) 118 } 119 120 func TestUint64NotZero(t *testing.T) { 121 assert := assert.New(t) 122 123 var verr error 124 var val uint64 = 5 125 verr = Uint64(&val).NotZero()() 126 assert.Nil(verr) 127 128 verr = Uint64(nil).NotZero()() 129 assert.NotNil(verr) 130 assert.Nil(ErrValue(verr)) 131 assert.Equal(ErrUint64NotZero, ErrCause(verr)) 132 133 val = 0 134 verr = Uint64(&val).NotZero()() 135 assert.NotNil(verr) 136 assert.NotNil(ErrValue(verr)) 137 assert.Equal(ErrUint64NotZero, ErrCause(verr)) 138 }