github.com/aavshr/aws-sdk-go@v1.41.3/service/s3/bench_test.go (about)

     1  package s3
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/aavshr/aws-sdk-go/aws"
     9  	"github.com/aavshr/aws-sdk-go/awstesting/unit"
    10  )
    11  
    12  func BenchmarkPresign_GetObject(b *testing.B) {
    13  	sess := unit.Session
    14  	svc := New(sess)
    15  
    16  	for i := 0; i < b.N; i++ {
    17  		req, _ := svc.GetObjectRequest(&GetObjectInput{
    18  			Bucket: aws.String("mock-bucket"),
    19  			Key:    aws.String("mock-key"),
    20  		})
    21  
    22  		u, h, err := req.PresignRequest(15 * time.Minute)
    23  		if err != nil {
    24  			b.Fatalf("expect no error, got %v", err)
    25  		}
    26  		if len(u) == 0 {
    27  			b.Fatalf("expect url, got none")
    28  		}
    29  		if len(h) != 0 {
    30  			b.Fatalf("no signed headers, got %v", h)
    31  		}
    32  	}
    33  }
    34  
    35  func BenchmarkPresign_PutObject(b *testing.B) {
    36  	sess := unit.Session
    37  	svc := New(sess)
    38  
    39  	body := make([]byte, 1024*1024*20)
    40  	for i := 0; i < b.N; i++ {
    41  		req, _ := svc.PutObjectRequest(&PutObjectInput{
    42  			Bucket: aws.String("mock-bucket"),
    43  			Key:    aws.String("mock-key"),
    44  			Body:   bytes.NewReader(body),
    45  		})
    46  
    47  		u, h, err := req.PresignRequest(15 * time.Minute)
    48  		if err != nil {
    49  			b.Fatalf("expect no error, got %v", err)
    50  		}
    51  		if len(u) == 0 {
    52  			b.Fatalf("expect url, got none")
    53  		}
    54  		if len(h) == 0 {
    55  			b.Fatalf("expect signed header, got none")
    56  		}
    57  	}
    58  }