github.com/blend/go-sdk@v1.20220411.3/async/interceptor_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 "testing" 12 13 "github.com/blend/go-sdk/assert" 14 ) 15 16 func Test_Interceptors(t *testing.T) { 17 its := assert.New(t) 18 19 var calls []string 20 a := InterceptorFunc(func(i Actioner) Actioner { 21 calls = append(calls, "a") 22 return i 23 }) 24 b := InterceptorFunc(func(i Actioner) Actioner { 25 calls = append(calls, "b") 26 return i 27 }) 28 c := InterceptorFunc(func(i Actioner) Actioner { 29 calls = append(calls, "c") 30 return i 31 }) 32 i := Interceptors(a, b, c) 33 i.Intercept(new(NoopActioner)) 34 its.Equal([]string{"a", "b", "c"}, calls) 35 } 36 37 func Test_Interceptors_all_nil(t *testing.T) { 38 its := assert.New(t) 39 40 i := Interceptors(nil, nil, nil) 41 its.Nil(i) 42 } 43 44 func Test_Interceptors_some_nil(t *testing.T) { 45 its := assert.New(t) 46 47 var calls []string 48 a := InterceptorFunc(func(i Actioner) Actioner { 49 calls = append(calls, "a") 50 return i 51 }) 52 c := InterceptorFunc(func(i Actioner) Actioner { 53 calls = append(calls, "c") 54 return i 55 }) 56 i := Interceptors(nil, a, nil, c) 57 i.Intercept(new(NoopActioner)) 58 its.Equal([]string{"a", "c"}, calls) 59 }