v8.run/go/exp@v0.0.26-0.20230226010534-afcdbd3f782d/sync2/runp_test.go (about) 1 package sync2 2 3 import ( 4 "errors" 5 "testing" 6 ) 7 8 func TestRunParallel(t *testing.T) { 9 type args struct { 10 data []uint64 11 fn func(uint64) error 12 } 13 14 var errTest = errors.New("test error") 15 16 tests := []struct { 17 name string 18 args args 19 want []error 20 }{ 21 { 22 name: "no errors", 23 args: args{ 24 data: []uint64{1, 2, 3, 4, 5}, 25 fn: func(uint64) error { 26 return nil 27 }, 28 }, 29 want: []error{}, 30 }, 31 { 32 name: "some errors", 33 args: args{ 34 data: []uint64{1, 2, 3, 4, 5}, 35 fn: func(i uint64) error { 36 if i%2 == 0 { 37 return nil 38 } 39 return errTest 40 }, 41 }, 42 want: []error{errTest, errTest, errTest}, 43 }, 44 } 45 for _, tt := range tests { 46 t.Run(tt.name, func(t *testing.T) { 47 if got := RunParallel(tt.args.data, tt.args.fn); len(got) != len(tt.want) { 48 t.Errorf("RunParallel() = %v, want %v", got, tt.want) 49 } 50 }) 51 } 52 }