github.com/blend/go-sdk@v1.20220411.3/validate/uuid_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 "github.com/blend/go-sdk/uuid" 15 ) 16 17 func TestUUIDRequired(t *testing.T) { 18 assert := assert.New(t) 19 20 var verr error 21 verr = UUID(nil).Required()() 22 assert.NotNil(verr) 23 assert.Equal(ErrUUIDRequired, ErrCause(verr)) 24 25 var empty uuid.UUID 26 verr = UUID(&empty).Required()() 27 assert.NotNil(verr) 28 assert.Equal(ErrUUIDRequired, ErrCause(verr)) 29 30 set := uuid.V4() 31 verr = UUID(&set).Required()() 32 assert.Nil(verr) 33 } 34 35 func TestUUIDForbidden(t *testing.T) { 36 assert := assert.New(t) 37 38 var verr error 39 verr = UUID(nil).Forbidden()() 40 assert.Nil(verr) 41 42 var empty uuid.UUID 43 verr = UUID(&empty).Forbidden()() 44 assert.Nil(verr) 45 46 set := uuid.V4() 47 verr = UUID(&set).Forbidden()() 48 assert.NotNil(verr) 49 assert.Equal(ErrUUIDForbidden, ErrCause(verr)) 50 } 51 52 func TestUUIDIsV4(t *testing.T) { 53 assert := assert.New(t) 54 55 var verr error 56 verr = UUID(nil).IsV4()() 57 assert.NotNil(verr) 58 assert.Equal(ErrUUIDV4, ErrCause(verr)) 59 60 var empty uuid.UUID 61 verr = UUID(&empty).IsV4()() 62 assert.NotNil(verr) 63 assert.Equal(ErrUUIDV4, ErrCause(verr)) 64 65 set := uuid.V4() 66 verr = UUID(&set).IsV4()() 67 assert.Nil(verr) 68 } 69 70 func TestUUIDIsVersion(t *testing.T) { 71 assert := assert.New(t) 72 version4 := uuid.V4().Version() 73 74 var verr error 75 verr = UUID(nil).IsVersion(version4)() 76 assert.NotNil(verr) 77 assert.Equal(ErrUUIDVersion, ErrCause(verr)) 78 79 var empty uuid.UUID 80 verr = UUID(&empty).IsVersion(version4)() 81 assert.NotNil(verr) 82 assert.Equal(ErrUUIDVersion, ErrCause(verr)) 83 84 set := uuid.V4() 85 verr = UUID(&set).IsVersion(version4)() 86 assert.Nil(verr) 87 }