File: bench_test.go

package info (click to toggle)
golang-github-aws-aws-sdk-go 1.44.133-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates
  • size: 245,296 kB
  • sloc: makefile: 120
file content (58 lines) | stat: -rw-r--r-- 1,194 bytes parent folder | download | duplicates (6)
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
57
58
package s3

import (
	"bytes"
	"testing"
	"time"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/awstesting/unit"
)

func BenchmarkPresign_GetObject(b *testing.B) {
	sess := unit.Session
	svc := New(sess)

	for i := 0; i < b.N; i++ {
		req, _ := svc.GetObjectRequest(&GetObjectInput{
			Bucket: aws.String("mock-bucket"),
			Key:    aws.String("mock-key"),
		})

		u, h, err := req.PresignRequest(15 * time.Minute)
		if err != nil {
			b.Fatalf("expect no error, got %v", err)
		}
		if len(u) == 0 {
			b.Fatalf("expect url, got none")
		}
		if len(h) != 0 {
			b.Fatalf("no signed headers, got %v", h)
		}
	}
}

func BenchmarkPresign_PutObject(b *testing.B) {
	sess := unit.Session
	svc := New(sess)

	body := make([]byte, 1024*1024*20)
	for i := 0; i < b.N; i++ {
		req, _ := svc.PutObjectRequest(&PutObjectInput{
			Bucket: aws.String("mock-bucket"),
			Key:    aws.String("mock-key"),
			Body:   bytes.NewReader(body),
		})

		u, h, err := req.PresignRequest(15 * time.Minute)
		if err != nil {
			b.Fatalf("expect no error, got %v", err)
		}
		if len(u) == 0 {
			b.Fatalf("expect url, got none")
		}
		if len(h) == 0 {
			b.Fatalf("expect signed header, got none")
		}
	}
}