github.com/vchain-us/vcn@v0.9.11-0.20210921212052-a2484d23c0b3/pkg/extractor/options_test.go (about) 1 /* 2 * Copyright (c) 2018-2020 vChain, Inc. All Rights Reserved. 3 * This software is released under GPL3. 4 * The full license information can be found under: 5 * https://www.gnu.org/licenses/gpl-3.0.en.html 6 * 7 */ 8 9 package extractor 10 11 import ( 12 "errors" 13 "testing" 14 15 "github.com/stretchr/testify/assert" 16 ) 17 18 type dummyOpts struct { 19 flag bool 20 } 21 22 func withTestOption() Option { 23 return func(o interface{}) error { 24 if oo, ok := o.(*dummyOpts); ok { 25 oo.flag = true 26 } 27 return nil 28 } 29 } 30 31 func withTestOptionWithError() Option { 32 return func(o interface{}) error { 33 return errors.New("some error") 34 } 35 } 36 37 func TestApply(t *testing.T) { 38 39 opts := &dummyOpts{} 40 41 err := Options([]Option{ 42 withTestOption(), 43 }).Apply(opts) 44 assert.NoError(t, err) 45 assert.True(t, opts.flag) 46 47 err = Options([]Option{ 48 withTestOptionWithError(), 49 }).Apply(opts) 50 assert.Error(t, err) 51 }