customizations_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package ec2_test
  2. import (
  3. "io/ioutil"
  4. "net/url"
  5. "regexp"
  6. "testing"
  7. "github.com/aws/aws-sdk-go/aws"
  8. "github.com/aws/aws-sdk-go/awstesting/unit"
  9. "github.com/aws/aws-sdk-go/service/ec2"
  10. )
  11. func TestCopySnapshotPresignedURL(t *testing.T) {
  12. svc := ec2.New(unit.Session, &aws.Config{Region: aws.String("us-west-2")})
  13. func() {
  14. defer func() {
  15. if r := recover(); r != nil {
  16. t.Fatalf("expect CopySnapshotRequest with nill")
  17. }
  18. }()
  19. // Doesn't panic on nil input
  20. req, _ := svc.CopySnapshotRequest(nil)
  21. req.Sign()
  22. }()
  23. req, _ := svc.CopySnapshotRequest(&ec2.CopySnapshotInput{
  24. SourceRegion: aws.String("us-west-1"),
  25. SourceSnapshotId: aws.String("snap-id"),
  26. })
  27. req.Sign()
  28. b, _ := ioutil.ReadAll(req.HTTPRequest.Body)
  29. q, _ := url.ParseQuery(string(b))
  30. u, _ := url.QueryUnescape(q.Get("PresignedUrl"))
  31. if e, a := "us-west-2", q.Get("DestinationRegion"); e != a {
  32. t.Errorf("expect %v, got %v", e, a)
  33. }
  34. if e, a := "us-west-1", q.Get("SourceRegion"); e != a {
  35. t.Errorf("expect %v, got %v", e, a)
  36. }
  37. r := regexp.MustCompile(`^https://ec2\.us-west-1\.amazonaws\.com/.+&DestinationRegion=us-west-2`)
  38. if !r.MatchString(u) {
  39. t.Errorf("expect %v to match, got %v", r.String(), u)
  40. }
  41. }