github.com/webdestroya/awsmocker@v0.2.6/received_request_test.go (about)

     1  package awsmocker_test
     2  
     3  import (
     4  	"bytes"
     5  	"context"
     6  	"testing"
     7  
     8  	"github.com/aws/aws-sdk-go-v2/service/ecs"
     9  	"github.com/stretchr/testify/require"
    10  	"github.com/webdestroya/awsmocker"
    11  )
    12  
    13  func TestReceivedRequest_DebugDump(t *testing.T) {
    14  	origWriter := awsmocker.DebugOutputWriter
    15  	origDebugMode := awsmocker.GlobalDebugMode
    16  
    17  	t.Cleanup(func() {
    18  		awsmocker.DebugOutputWriter = origWriter
    19  		awsmocker.GlobalDebugMode = origDebugMode
    20  	})
    21  
    22  	buf := new(bytes.Buffer)
    23  	awsmocker.GlobalDebugMode = true
    24  	awsmocker.DebugOutputWriter = buf
    25  
    26  	// tables := []struct{}{}
    27  
    28  	// for _, table := range tables {
    29  
    30  	// }
    31  
    32  	info := awsmocker.Start(t, &awsmocker.MockerOptions{
    33  		SkipDefaultMocks: true,
    34  		ReturnAwsConfig:  true,
    35  		// V
    36  		Mocks: []*awsmocker.MockedEndpoint{
    37  			awsmocker.Mock_Failure("ecs", "ListClusters"),
    38  			awsmocker.Mock_Failure_WithCode(403, "ecs", "ListServices", "SomeCode", "SomeMessage"),
    39  		},
    40  	})
    41  
    42  	ecsClient := ecs.NewFromConfig(*info.AwsConfig)
    43  
    44  	_, err := ecsClient.ListClusters(context.TODO(), &ecs.ListClustersInput{})
    45  	require.Error(t, err)
    46  	require.ErrorContains(t, err, "AccessDenied")
    47  
    48  	debugStr := buf.String()
    49  	buf.Reset()
    50  	require.Contains(t, debugStr, "AWSMOCKER RECEIVED REQUEST:")
    51  	require.Contains(t, debugStr, "AWSMOCKER RESPONSE:")
    52  	require.Contains(t, debugStr, "POST")
    53  	require.Contains(t, debugStr, "ecs.us-east-1.amazonaws.com")
    54  	require.Contains(t, debugStr, "ListClusters")
    55  
    56  }