customizations_test.go 928 B

123456789101112131415161718192021222324252627282930313233343536
  1. package ec2_test
  2. import (
  3. "io/ioutil"
  4. "net/url"
  5. "testing"
  6. "github.com/aws/aws-sdk-go/aws"
  7. "github.com/aws/aws-sdk-go/internal/test/unit"
  8. "github.com/aws/aws-sdk-go/service/ec2"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. var _ = unit.Imported
  12. func TestCopySnapshotPresignedURL(t *testing.T) {
  13. svc := ec2.New(&aws.Config{Region: aws.String("us-west-2")})
  14. assert.NotPanics(t, func() {
  15. // Doesn't panic on nil input
  16. req, _ := svc.CopySnapshotRequest(nil)
  17. req.Sign()
  18. })
  19. req, _ := svc.CopySnapshotRequest(&ec2.CopySnapshotInput{
  20. SourceRegion: aws.String("us-west-1"),
  21. SourceSnapshotId: aws.String("snap-id"),
  22. })
  23. req.Sign()
  24. b, _ := ioutil.ReadAll(req.HTTPRequest.Body)
  25. q, _ := url.ParseQuery(string(b))
  26. url, _ := url.QueryUnescape(q.Get("PresignedUrl"))
  27. assert.Equal(t, "us-west-2", q.Get("DestinationRegion"))
  28. assert.Regexp(t, `^https://ec2\.us-west-1\.amazon.+&DestinationRegion=us-west-2`, url)
  29. }