Exemplo n.º 1
0
func TestMain(m *testing.M) {
	db = dynamodb.New(&aws.Config{
		Region:      "mock-region",
		Credentials: aws.DetectCreds("AKID", "SECRET", ""),
		MaxRetries:  2,
	})
	db.Handlers.Send.Clear() // mock sending

	os.Exit(m.Run())
}
Exemplo n.º 2
0
func TestValidateCRC32DoesNotMatchNoComputeChecksum(t *testing.T) {
	svc := dynamodb.New(&aws.Config{
		Region:                  "mock-region",
		Credentials:             aws.DetectCreds("AKID", "SECRET", ""),
		MaxRetries:              2,
		DisableComputeChecksums: true,
	})
	svc.Handlers.Send.Clear() // mock sending

	req := mockCRCResponse(svc, 200, `{"TableNames":["A"]}`, "1234")
	assert.NoError(t, req.Error)

	assert.Equal(t, 0, int(req.RetryCount))

	// CRC check disabled. Does not affect output parsing
	out := req.Data.(*dynamodb.ListTablesOutput)
	assert.Equal(t, "A", *out.TableNames[0])
}
Exemplo n.º 3
0
func TestSendMessageChecksumInvalidNoValidation(t *testing.T) {
	s := sqs.New(&aws.Config{
		Region:                  "mock-region",
		Credentials:             aws.DetectCreds("AKID", "SECRET", ""),
		DisableParamValidation:  true,
		DisableComputeChecksums: true,
	})
	s.Handlers.Send.Clear()

	req, _ := s.SendMessageRequest(&sqs.SendMessageInput{
		MessageBody: aws.String("test"),
	})
	req.Handlers.Send.PushBack(func(r *aws.Request) {
		body := ioutil.NopCloser(bytes.NewReader([]byte("")))
		r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
		r.Data = &sqs.SendMessageOutput{
			MD5OfMessageBody: aws.String("000"),
			MessageID:        aws.String("12345"),
		}
	})
	err := req.Send()
	assert.NoError(t, err)
}
Exemplo n.º 4
0
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)
}
Exemplo n.º 5
0
import (
	"bytes"
	"io/ioutil"
	"net/http"
	"testing"

	"github.com/datacratic/aws-sdk-go/aws"
	"github.com/datacratic/aws-sdk-go/service/sqs"
	"github.com/stretchr/testify/assert"
)

var svc = func() *sqs.SQS {
	s := sqs.New(&aws.Config{
		Region:                 "mock-region",
		Credentials:            aws.DetectCreds("AKID", "SECRET", ""),
		DisableParamValidation: true,
	})
	s.Handlers.Send.Clear()
	return s
}()

func TestSendMessageChecksum(t *testing.T) {
	req, _ := svc.SendMessageRequest(&sqs.SendMessageInput{
		MessageBody: aws.String("test"),
	})
	req.Handlers.Send.PushBack(func(r *aws.Request) {
		body := ioutil.NopCloser(bytes.NewReader([]byte("")))
		r.HTTPResponse = &http.Response{StatusCode: 200, Body: body}
		r.Data = &sqs.SendMessageOutput{
			MD5OfMessageBody: aws.String("098f6bcd4621d373cade4e832627b4f6"),