File: get_code_binding_source_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go-v2 1.17.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 384,244 kB
  • sloc: java: 13,538; makefile: 400; sh: 137
file content (56 lines) | stat: -rw-r--r-- 1,277 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package schemas

import (
	"bytes"
	"context"
	"io/ioutil"
	"net/http"
	"testing"

	"github.com/aws/aws-sdk-go-v2/service/schemas"
	"github.com/aws/smithy-go/ptr"
	smithyhttp "github.com/aws/smithy-go/transport/http"
)

func init() {
	largeBytePayload = make([]byte, 1024*1024*12)
}

var largeBytePayload []byte

func BenchmarkGetCodeBindingSource(b *testing.B) {
	client := schemas.New(schemas.Options{
		Region: "us-west-2",
		HTTPClient: smithyhttp.ClientDoFunc(
			func(r *http.Request) (*http.Response, error) {
				return newGetCodeBindingSourceHTTPResponse(largeBytePayload), nil
			}),
	})

	ctx := context.Background()
	params := schemas.GetCodeBindingSourceInput{
		Language:     ptr.String("fooLanguage"),
		RegistryName: ptr.String("fooRegistry"),
		SchemaName:   ptr.String("fooSchema"),
	}

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_, err := client.GetCodeBindingSource(ctx, &params)
		if err != nil {
			b.Fatalf("failed to send: %v", err)
		}
	}

}

func newGetCodeBindingSourceHTTPResponse(payload []byte) *http.Response {
	return &http.Response{
		StatusCode: 200,
		Header: map[string][]string{
			"Content-Type": {"application/octet-stream"},
		},
		ContentLength: int64(len(payload)),
		Body:          ioutil.NopCloser(bytes.NewReader(payload)),
	}
}