func TestMakingABasicRequest(t *testing.T) { client := ec2.New(nil) resp, e := client.DescribeRegions(&ec2.DescribeRegionsInput{}) err := aws.Error(e) _, _, _ = resp, e, err // avoid unused warnings assert.NoError(t, nil, err) }
func TestErrorHandling(t *testing.T) { client := ec2.New(nil) resp, e := client.DescribeInstances(&ec2.DescribeInstancesInput{ InstanceIDs: []*string{ aws.String("i-12345678"), }, }) err := aws.Error(e) _, _, _ = resp, e, err // avoid unused warnings assert.NotEqual(t, nil, err) assert.Equal(t, "InvalidInstanceID.NotFound", err.Code) utilassert.Match(t, "The instance ID 'i-12345678' does not exist", err.Message) }
func TestCopySnapshotPresignedURL(t *testing.T) { svc := ec2.New(&aws.Config{ Credentials: aws.DetectCreds("AKID", "SECRET", ""), Region: "us-west-2", }) assert.NotPanics(t, func() { // Doesn't panic on nil input req, _ := svc.CopySnapshotRequest(nil) req.Sign() }) req, _ := svc.CopySnapshotRequest(&ec2.CopySnapshotInput{ SourceRegion: aws.String("us-west-1"), SourceSnapshotID: aws.String("snap-id"), }) req.Sign() b, _ := ioutil.ReadAll(req.HTTPRequest.Body) q, _ := url.ParseQuery(string(b)) url, _ := url.QueryUnescape(q.Get("PresignedUrl")) assert.Equal(t, "us-west-2", q.Get("DestinationRegion")) assert.Regexp(t, `^https://ec2\.us-west-1\.amazon.+&DestinationRegion=us-west-2`, url) }