// Code generated by smithy-go-codegen DO NOT EDIT.

package awsrestjson

import (
	"bytes"
	"context"
	"encoding/base64"
	"github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream"
	"github.com/aws/aws-sdk-go-v2/credentials"
	"github.com/aws/aws-sdk-go-v2/internal/protocoltest/awsrestjson/types"
	"github.com/aws/smithy-go/middleware"
	"github.com/aws/smithy-go/ptr"
	smithytesting "github.com/aws/smithy-go/testing"
	"testing"
	"time"
)

func TestEventStream_DuplexStream_DuplexBooleanHeaderInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
		BooleanHeader: ptr.Bool(true),
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAASwAAADv7Cl8VDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMNYm9vbGVhbkhlYWRlcgC4J9Ws")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexByteHeaderInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
		ByteHeader: ptr.Int8(1),
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAASQAAADlvxG1ZDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMKYnl0ZUhlYWRlcgIBKFTmjg==")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexShortHeaderInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
		ShortHeader: ptr.Int16(2),
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAASwAAADv7Cl8VDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMLc2hvcnRIZWFkZXIDAAL1ETsK")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexIntegerHeaderInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
		IntHeader: ptr.Int32(3),
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAASwAAADv7Cl8VDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMJaW50SGVhZGVyBAAAAAPlyUrb")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexLongHeaderInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
		LongHeader: ptr.Int64(4294967294),
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAAUAAAAEAr7VEyDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMKbG9uZ0hlYWRlcgUAAAAA/////udnd/I=")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexBlobHeaderInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
		BlobHeader: []byte("foo"),
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAATQAAAD2dKQ+ADTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMKYmxvYkhlYWRlcgYAA2Zvb5sbbGM=")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexStringHeaderInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
		StringHeader: ptr.String("foo"),
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAATwAAAD8J5z3MDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMMc3RyaW5nSGVhZGVyBwADZm9vxT+2MA==")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexTimestampHeaderInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
		TimestampHeader: ptr.Time(func() time.Time { t, _ := time.Parse(time.RFC3339, "2024-10-31T14:15:14Z"); return t }()),
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAAVQAAAEWTZyrNDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMPdGltZXN0YW1wSGVhZGVyCAAAAZLi7jFQ6uV3Eg==")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexMultipleHeaderInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
		BooleanHeader: ptr.Bool(true),
		StringHeader:  ptr.String("foo"),
		BlobHeader:    []byte("bar"),
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAAbwAAAF+FlHOQDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMNYm9vbGVhbkhlYWRlcgAMc3RyaW5nSGVhZGVyBwADZm9vCmJsb2JIZWFkZXIGAANiYXIDXbo7")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexStringPayloadInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberStringPayload{Value: types.StringPayloadEvent{
		Payload: ptr.String("foo"),
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAAYAAAAE30fZUJDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcADXN0cmluZ1BheWxvYWQNOmNvbnRlbnQtdHlwZQcACnRleHQvcGxhaW5mb29G1ELr")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexBlobPayloadInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberBlobPayload{Value: types.BlobPayloadEvent{
		Payload: []byte("bar"),
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAAbAAAAFkrV6x1DTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAC2Jsb2JQYXlsb2FkDTpjb250ZW50LXR5cGUHABhhcHBsaWNhdGlvbi9vY3RldC1zdHJlYW1iYXJv5nGJ")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexStructurePayloadInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberStructurePayload{Value: types.StructurePayloadEvent{
		Payload: &types.PayloadStructure{
			StructureMember: ptr.String("foo"),
		},
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAAfwAAAFacqFy2DTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAEHN0cnVjdHVyZVBheWxvYWQNOmNvbnRlbnQtdHlwZQcAEGFwcGxpY2F0aW9uL2pzb257InN0cnVjdHVyZU1lbWJlciI6ImZvbyJ9rcIRVA==")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexUnionPayloadInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberUnionPayload{Value: types.UnionPayloadEvent{
		Payload: &types.PayloadUnionMemberUnionMember{Value: "bar"},
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAAdwAAAFKrtdNuDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcADHVuaW9uUGF5bG9hZA06Y29udGVudC10eXBlBwAQYXBwbGljYXRpb24vanNvbnsidW5pb25NZW1iZXIiOiJiYXIifcZDMD4=")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexHeadersAndExplicitPayloadInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberHeadersAndExplicitPayload{Value: types.HeadersAndExplicitPayloadEvent{
		Header: ptr.String("foo"),
		Payload: &types.PayloadStructure{
			StructureMember: ptr.String("bar"),
		},
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAAlQAAAGw4wFp6DTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAGWhlYWRlcnNBbmRFeHBsaWNpdFBheWxvYWQNOmNvbnRlbnQtdHlwZQcAEGFwcGxpY2F0aW9uL2pzb24GaGVhZGVyBwADZm9veyJzdHJ1Y3R1cmVNZW1iZXIiOiJiYXIifTafKXs=")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexHeadersAndImplicitPayloadInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	sendEvent := &types.EventStreamMemberHeadersAndImplicitPayload{Value: types.HeadersAndImplicitPayloadEvent{
		Header:  ptr.String("foo"),
		Payload: ptr.String("bar"),
	}}
	if err := resp.GetStream().Send(context.Background(), sendEvent); err != nil {
		t.Fatalf("failed to send event: %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

	requestMsgs, err := mock.readRequestEvents()
	if err != nil {
		t.Fatalf("failed to read request events: %v", err)
	}
	if len(requestMsgs) != 1 {
		t.Fatalf("expected 1 request events, got %d", len(requestMsgs))
	}

	{
		expectRaw, _ := base64.StdEncoding.DecodeString("AAAAjQAAAGxoUIY5DTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAGWhlYWRlcnNBbmRJbXBsaWNpdFBheWxvYWQNOmNvbnRlbnQtdHlwZQcAEGFwcGxpY2F0aW9uL2pzb24GaGVhZGVyBwADZm9veyJwYXlsb2FkIjoiYmFyIn15lZtT")
		expectMsg, _ := eventstream.NewDecoder().Decode(bytes.NewReader(expectRaw), make([]byte, 1024))
		actualMsg := requestMsgs[0]
		for _, eh := range expectMsg.Headers {
			ah := actualMsg.Headers.Get(eh.Name)
			if ah == nil {
				t.Errorf("request event %d: missing header %q", 0, eh.Name)
			}
			if ah != nil && ah.String() != eh.Value.String() {
				t.Errorf("request event %d: header %q = %v, want %v", 0, eh.Name, ah, eh.Value)
			}
		}
		if !bytes.Equal(actualMsg.Payload, expectMsg.Payload) {
			t.Errorf("request event %d: payload mismatch, got %q want %q", 0, actualMsg.Payload, expectMsg.Payload)
		}
	}
}

func TestEventStream_DuplexStream_DuplexClientErrorInput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	mock.CloseResponse()
	resp.GetStream().Close()

}

func TestEventStream_DuplexStream_DuplexBooleanHeaderOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAASwAAADv7Cl8VDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMNYm9vbGVhbkhlYWRlcgC4J9Ws")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
				BooleanHeader: ptr.Bool(true),
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexByteHeaderOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAASQAAADlvxG1ZDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMKYnl0ZUhlYWRlcgIBKFTmjg==")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
				ByteHeader: ptr.Int8(1),
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexShortHeaderOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAASwAAADv7Cl8VDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMLc2hvcnRIZWFkZXIDAAL1ETsK")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
				ShortHeader: ptr.Int16(2),
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexIntegerHeaderOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAASwAAADv7Cl8VDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMJaW50SGVhZGVyBAAAAAPlyUrb")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
				IntHeader: ptr.Int32(3),
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexLongHeaderOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAUAAAAEAr7VEyDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMKbG9uZ0hlYWRlcgUAAAAA/////udnd/I=")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
				LongHeader: ptr.Int64(4294967294),
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexBlobHeaderOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAATQAAAD2dKQ+ADTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMKYmxvYkhlYWRlcgYAA2Zvb5sbbGM=")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
				BlobHeader: []byte("foo"),
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexStringHeaderOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAATwAAAD8J5z3MDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMMc3RyaW5nSGVhZGVyBwADZm9vxT+2MA==")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
				StringHeader: ptr.String("foo"),
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexTimestampHeaderOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAVQAAAEWTZyrNDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMPdGltZXN0YW1wSGVhZGVyCAAAAZLi7jFQ6uV3Eg==")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
				TimestampHeader: ptr.Time(func() time.Time { t, _ := time.Parse(time.RFC3339, "2024-10-31T14:15:14Z"); return t }()),
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexMultipleHeaderOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAbwAAAF+FlHOQDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAB2hlYWRlcnMNYm9vbGVhbkhlYWRlcgAMc3RyaW5nSGVhZGVyBwADZm9vCmJsb2JIZWFkZXIGAANiYXIDXbo7")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberHeaders{Value: types.HeadersEvent{
				BooleanHeader: ptr.Bool(true),
				StringHeader:  ptr.String("foo"),
				BlobHeader:    []byte("bar"),
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexStringPayloadOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAYAAAAE30fZUJDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcADXN0cmluZ1BheWxvYWQNOmNvbnRlbnQtdHlwZQcACnRleHQvcGxhaW5mb29G1ELr")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberStringPayload{Value: types.StringPayloadEvent{
				Payload: ptr.String("foo"),
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexBlobPayloadOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAbAAAAFkrV6x1DTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAC2Jsb2JQYXlsb2FkDTpjb250ZW50LXR5cGUHABhhcHBsaWNhdGlvbi9vY3RldC1zdHJlYW1iYXJv5nGJ")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberBlobPayload{Value: types.BlobPayloadEvent{
				Payload: []byte("bar"),
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexStructurePayloadOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAfwAAAFacqFy2DTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAEHN0cnVjdHVyZVBheWxvYWQNOmNvbnRlbnQtdHlwZQcAEGFwcGxpY2F0aW9uL2pzb257InN0cnVjdHVyZU1lbWJlciI6ImZvbyJ9rcIRVA==")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberStructurePayload{Value: types.StructurePayloadEvent{
				Payload: &types.PayloadStructure{
					StructureMember: ptr.String("foo"),
				},
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexUnionPayloadOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAdwAAAFKrtdNuDTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcADHVuaW9uUGF5bG9hZA06Y29udGVudC10eXBlBwAQYXBwbGljYXRpb24vanNvbnsidW5pb25NZW1iZXIiOiJiYXIifcZDMD4=")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberUnionPayload{Value: types.UnionPayloadEvent{
				Payload: &types.PayloadUnionMemberUnionMember{Value: "bar"},
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexHeadersAndExplicitPayloadOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAlQAAAGw4wFp6DTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAGWhlYWRlcnNBbmRFeHBsaWNpdFBheWxvYWQNOmNvbnRlbnQtdHlwZQcAEGFwcGxpY2F0aW9uL2pzb24GaGVhZGVyBwADZm9veyJzdHJ1Y3R1cmVNZW1iZXIiOiJiYXIifTafKXs=")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberHeadersAndExplicitPayload{Value: types.HeadersAndExplicitPayloadEvent{
				Header: ptr.String("foo"),
				Payload: &types.PayloadStructure{
					StructureMember: ptr.String("bar"),
				},
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexHeadersAndImplicitPayloadOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAjQAAAGxoUIY5DTptZXNzYWdlLXR5cGUHAAVldmVudAs6ZXZlbnQtdHlwZQcAGWhlYWRlcnNBbmRJbXBsaWNpdFBheWxvYWQNOmNvbnRlbnQtdHlwZQcAEGFwcGxpY2F0aW9uL2pzb24GaGVhZGVyBwADZm9veyJwYXlsb2FkIjoiYmFyIn15lZtT")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		receivedEvents++
		switch receivedEvents {
		case 1:
			expect := &types.EventStreamMemberHeadersAndImplicitPayload{Value: types.HeadersAndImplicitPayloadEvent{
				Header:  ptr.String("foo"),
				Payload: ptr.String("bar"),
			}}
			if err := smithytesting.CompareValues(expect, event); err != nil {
				t.Errorf("event %d mismatch: %v", receivedEvents, err)
			}

		}
	}

	if err := resp.GetStream().Err(); err != nil {
		t.Fatalf("expect no stream error, got %v", err)
	}
	if receivedEvents != 1 {
		t.Fatalf("expected 1 events, got %d", receivedEvents)
	}
}

func TestEventStream_DuplexStream_DuplexClientErrorOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAdAAAAFObEpkoDTptZXNzYWdlLXR5cGUHAAlleGNlcHRpb24POmV4Y2VwdGlvbi10eXBlBwAFZXJyb3INOmNvbnRlbnQtdHlwZQcAEGFwcGxpY2F0aW9uL2pzb257Im1lc3NhZ2UiOiJmb28ifTua1S8=")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		_ = event
		receivedEvents++
	}

	if err := resp.GetStream().Err(); err == nil {
		t.Fatal("expected stream error, got none")
	}
}

func TestEventStream_DuplexStream_DuplexClientUnexpectedErrorOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAbwAAAF+FlHOQDTptZXNzYWdlLXR5cGUHAAVlcnJvcgs6ZXJyb3ItY29kZQcADmludGVybmFsLWVycm9yDjplcnJvci1tZXNzYWdlBwAaQW4gdW5rbm93biBlcnJvciBvY2N1cnJlZC4kun0t")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		_ = event
		receivedEvents++
	}

	if err := resp.GetStream().Err(); err == nil {
		t.Fatal("expected stream error, got none")
	}
}

func TestEventStream_DuplexStream_DuplexMissingMessageTypeOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAfwAAAFacqFy2CzpldmVudC10eXBlBwAZaGVhZGVyc0FuZEV4cGxpY2l0UGF5bG9hZA06Y29udGVudC10eXBlBwAQYXBwbGljYXRpb24vanNvbgZoZWFkZXIHAANmb297InN0cnVjdHVyZU1lbWJlciI6ImJhciJ98LexJg==")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		_ = event
		receivedEvents++
	}

	if err := resp.GetStream().Err(); err == nil {
		t.Fatal("expected stream error, got none")
	}
}

func TestEventStream_DuplexStream_DuplexMalformedMessageTypeOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAlQAAAGw4wFp6DTptZXNzYWdlLXR5cGUGAAVldmVudAs6ZXZlbnQtdHlwZQcAGWhlYWRlcnNBbmRFeHBsaWNpdFBheWxvYWQNOmNvbnRlbnQtdHlwZQcAEGFwcGxpY2F0aW9uL2pzb24GaGVhZGVyBwADZm9veyJzdHJ1Y3R1cmVNZW1iZXIiOiJiYXIifVwdfzU=")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		_ = event
		receivedEvents++
	}

	if err := resp.GetStream().Err(); err == nil {
		t.Fatal("expected stream error, got none")
	}
}

func TestEventStream_DuplexStream_DuplexMissingEventTypeOutput(t *testing.T) {
	mock := newEventstreamMockHTTPClient()
	defer mock.CloseResponse()
	mock.KeepResponseOpen = true
	mock.ResponseEvents = []eventstream.Message{
		func() eventstream.Message {
			raw, _ := base64.StdEncoding.DecodeString("AAAAbQAAAER1MekcDTptZXNzYWdlLXR5cGUHAAVldmVudA06Y29udGVudC10eXBlBwAQYXBwbGljYXRpb24vanNvbgZoZWFkZXIHAANmb297InN0cnVjdHVyZU1lbWJlciI6ImJhciJ9riy0Gg==")
			msg, err := eventstream.NewDecoder().Decode(bytes.NewReader(raw), make([]byte, 1024))
			if err != nil {
				panic(err)
			}
			return msg
		}(),
	}

	client := New(Options{
		HTTPClient:         mock,
		Credentials:        credentials.NewStaticCredentialsProvider("AKID", "SECRET", "SESSION"),
		EndpointResolverV2: &protocolTestEndpointResolver{URL: "http://localhost"},
		APIOptions: []func(*middleware.Stack) error{
			func(s *middleware.Stack) error {
				s.Finalize.Remove("Retry")
				s.Initialize.Remove("OperationInputValidation")
				return nil
			},
		},
	})

	resp, err := client.DuplexStream(context.Background(), &DuplexStreamInput{})
	if err != nil {
		t.Fatalf("expect no error, got %v", err)
	}
	defer resp.GetStream().Close()
	mock.CloseResponse()

	var receivedEvents int
	for event := range resp.GetStream().Events() {
		_ = event
		receivedEvents++
	}

	if err := resp.GetStream().Err(); err == nil {
		t.Fatal("expected stream error, got none")
	}
}

func TestEventStream_DuplexStream_DuplexMalformedEventTypeOutput(t *testing.T) {
	t.Skip("skipped, see SKIP_TESTS in EventStreamProtocolTestGenerator")
}
