github.com/blend/go-sdk@v1.20220411.3/async/errors_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 async 9 10 import ( 11 "fmt" 12 "testing" 13 14 "github.com/blend/go-sdk/assert" 15 "github.com/blend/go-sdk/ex" 16 ) 17 18 func Test_Errors_All(t *testing.T) { 19 its := assert.New(t) 20 21 errors := Errors(make(chan error, 5)) 22 its.Nil(errors.All()) 23 errors <- nil 24 errors <- fmt.Errorf("this is just a test 0") 25 errors <- nil 26 errors <- fmt.Errorf("this is just a test 1") 27 errors <- nil 28 29 allErr := errors.All() 30 its.NotNil(allErr) 31 32 typed, ok := allErr.(ex.Multi) 33 its.True(ok) 34 its.Len(typed, 2) 35 its.Equal("this is just a test 0", ex.ErrClass(typed[0]).Error()) 36 its.Equal("this is just a test 1", ex.ErrClass(typed[1]).Error()) 37 } 38 39 func Test_Errors_First(t *testing.T) { 40 its := assert.New(t) 41 42 errors := Errors(make(chan error, 5)) 43 its.Nil(errors.All()) 44 errors <- nil 45 errors <- fmt.Errorf("this is just a test 0") 46 errors <- nil 47 errors <- fmt.Errorf("this is just a test 1") 48 errors <- nil 49 50 firstErr := errors.First() 51 its.NotNil(firstErr) 52 53 typed, ok := firstErr.(*ex.Ex) 54 its.True(ok) 55 its.Equal("this is just a test 0", ex.ErrClass(typed).Error()) 56 }