github.com/newrelic/go-agent@v3.26.0+incompatible/internal_errors_13_test.go (about)

     1  // Copyright 2020 New Relic Corporation. All rights reserved.
     2  // SPDX-License-Identifier: Apache-2.0
     3  
     4  // +build go1.13
     5  
     6  package newrelic
     7  
     8  import (
     9  	"fmt"
    10  	"testing"
    11  
    12  	"github.com/newrelic/go-agent/internal"
    13  )
    14  
    15  func TestNoticedWrappedError(t *testing.T) {
    16  	gamma := func() error {
    17  		return Error{
    18  			Message: "socket error",
    19  			Class:   "socketError",
    20  			Attributes: map[string]interface{}{
    21  				"zip": "zap",
    22  			},
    23  		}
    24  	}
    25  	beta := func() error { return fmt.Errorf("problem in beta: %w", gamma()) }
    26  	alpha := func() error { return fmt.Errorf("problem in alpha: %w", beta()) }
    27  
    28  	app := testApp(nil, nil, t)
    29  	txn := app.StartTransaction("hello", nil, nil)
    30  	err := txn.NoticeError(alpha())
    31  	if nil != err {
    32  		t.Error(err)
    33  	}
    34  	txn.End()
    35  	app.ExpectErrors(t, []internal.WantError{{
    36  		TxnName: "OtherTransaction/Go/hello",
    37  		Msg:     "problem in alpha: problem in beta: socket error",
    38  		Klass:   "socketError",
    39  		UserAttributes: map[string]interface{}{
    40  			"zip": "zap",
    41  		},
    42  	}})
    43  	app.ExpectErrorEvents(t, []internal.WantEvent{{
    44  		Intrinsics: map[string]interface{}{
    45  			"error.class":     "socketError",
    46  			"error.message":   "problem in alpha: problem in beta: socket error",
    47  			"transactionName": "OtherTransaction/Go/hello",
    48  		},
    49  		UserAttributes: map[string]interface{}{
    50  			"zip": "zap",
    51  		},
    52  	}})
    53  	app.ExpectMetrics(t, backgroundErrorMetrics)
    54  }