github.com/blend/go-sdk@v1.20220411.3/ex/option_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 ex 9 10 import ( 11 "fmt" 12 "testing" 13 14 "github.com/blend/go-sdk/assert" 15 ) 16 17 func TestOptMessage(t *testing.T) { 18 assert := assert.New(t) 19 20 ex := &Ex{} 21 22 OptMessage("a message", " bar")(ex) 23 assert.Equal("a message bar", ex.Message) 24 } 25 26 func TestOptMessagef(t *testing.T) { 27 assert := assert.New(t) 28 29 ex := &Ex{} 30 31 OptMessagef("a message %s", "bar")(ex) 32 assert.Equal("a message bar", ex.Message) 33 } 34 35 func TestOptStackTrace(t *testing.T) { 36 assert := assert.New(t) 37 38 ex := &Ex{} 39 40 OptStackTrace(StackStrings([]string{"first", "second"}))(ex) 41 assert.NotNil(ex.StackTrace) 42 assert.Equal([]string{"first", "second"}, ex.StackTrace.Strings()) 43 } 44 45 func TestOptInner(t *testing.T) { 46 assert := assert.New(t) 47 48 ex := &Ex{} 49 50 OptInner(fmt.Errorf("this is only a test"))(ex) 51 assert.NotNil(ex.Inner) 52 } 53 54 func TestOptInnerClass(t *testing.T) { 55 assert := assert.New(t) 56 57 ex := &Ex{} 58 59 OptInnerClass(fmt.Errorf("this is only a test"))(ex) 60 assert.NotNil(ex.Inner) 61 assert.Nil(ErrStackTrace(ex.Inner)) 62 }