github.com/blend/go-sdk@v1.20220411.3/ex/stack_trace_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 TestGetStackTrace(t *testing.T) { 18 assert := assert.New(t) 19 20 assert.NotEmpty(GetStackTrace()) 21 } 22 23 func TestStackStrings(t *testing.T) { 24 assert := assert.New(t) 25 26 stack := []string{ 27 "foo", 28 "bar", 29 "baz", 30 } 31 32 stackStrings := StackStrings(stack) 33 34 assert.Equal("\nfoo\nbar\nbaz", fmt.Sprintf("%+v", stackStrings)) 35 assert.Equal("[]string{\"foo\", \"bar\", \"baz\"}", fmt.Sprintf("%#v", stackStrings)) 36 assert.Equal("\nfoo\nbar\nbaz", fmt.Sprintf("%v", stackStrings)) 37 assert.Equal([]string{"foo", "bar", "baz"}, stackStrings) 38 } 39 40 func TestExceptionWithStackStrings(t *testing.T) { 41 assert := assert.New(t) 42 43 stack := []string{ 44 "foo", 45 "bar", 46 "baz", 47 } 48 49 ex := As(New("foo", OptStackTrace(StackStrings(stack)))) 50 51 values := ex.Decompose() 52 assert.NotEmpty(values["StackTrace"]) 53 assert.NotNil(ex.StackTrace) 54 }