customizations_test.go 974 B

1234567891011121314151617181920212223242526272829303132333435
  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/awstesting/unit"
  8. "github.com/aws/aws-sdk-go/service/ec2"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestCopySnapshotPresignedURL(t *testing.T) {
  12. svc := ec2.New(unit.Session, &aws.Config{Region: aws.String("us-west-2")})
  13. assert.NotPanics(t, func() {
  14. // Doesn't panic on nil input
  15. req, _ := svc.CopySnapshotRequest(nil)
  16. req.Sign()
  17. })
  18. req, _ := svc.CopySnapshotRequest(&ec2.CopySnapshotInput{
  19. SourceRegion: aws.String("us-west-1"),
  20. SourceSnapshotId: aws.String("snap-id"),
  21. })
  22. req.Sign()
  23. b, _ := ioutil.ReadAll(req.HTTPRequest.Body)
  24. q, _ := url.ParseQuery(string(b))
  25. u, _ := url.QueryUnescape(q.Get("PresignedUrl"))
  26. assert.Equal(t, "us-west-2", q.Get("DestinationRegion"))
  27. assert.Equal(t, "us-west-1", q.Get("SourceRegion"))
  28. assert.Regexp(t, `^https://ec2\.us-west-1\.amazonaws\.com/.+&DestinationRegion=us-west-2`, u)
  29. }