github.com/kubernetes-incubator/kube-aws@v0.16.4/test/helper/s3.go (about)

     1  package helper
     2  
     3  import (
     4  	"bytes"
     5  	"fmt"
     6  	"github.com/aws/aws-sdk-go/service/s3"
     7  )
     8  
     9  type DummyS3ObjectPutterService struct {
    10  	ExpectedBucket        string
    11  	ExpectedKey           string
    12  	ExpectedBody          string
    13  	ExpectedContentType   string
    14  	ExpectedContentLength int64
    15  }
    16  
    17  func (s3Svc DummyS3ObjectPutterService) PutObject(input *s3.PutObjectInput) (*s3.PutObjectOutput, error) {
    18  
    19  	if s3Svc.ExpectedContentLength != *input.ContentLength {
    20  		return nil, fmt.Errorf(
    21  			"expected content length does not match supplied content length\nexpected=%v, supplied=%v",
    22  			s3Svc.ExpectedContentLength,
    23  			input.ContentLength,
    24  		)
    25  	}
    26  
    27  	if s3Svc.ExpectedBucket != *input.Bucket {
    28  		return nil, fmt.Errorf(
    29  			"expected bucket does not match supplied bucket\nexpected=%v, supplied=%v",
    30  			s3Svc.ExpectedBucket,
    31  			input.Bucket,
    32  		)
    33  	}
    34  
    35  	if s3Svc.ExpectedKey != *input.Key {
    36  		return nil, fmt.Errorf(
    37  			"expected key does not match supplied key\nexpected=%v, supplied=%v",
    38  			s3Svc.ExpectedKey,
    39  			*input.Key,
    40  		)
    41  	}
    42  
    43  	if s3Svc.ExpectedContentType != *input.ContentType {
    44  		return nil, fmt.Errorf(
    45  			"expected content type does not match supplied content type\nexpected=%v, supplied=%v",
    46  			s3Svc.ExpectedContentType,
    47  			input.ContentType,
    48  		)
    49  	}
    50  
    51  	buf := new(bytes.Buffer)
    52  	buf.ReadFrom(input.Body)
    53  	suppliedBody := buf.String()
    54  
    55  	if s3Svc.ExpectedBody != suppliedBody {
    56  		return nil, fmt.Errorf(
    57  			"expected body does not match supplied body\nexpected=%v, supplied=%v",
    58  			s3Svc.ExpectedBody,
    59  			suppliedBody,
    60  		)
    61  	}
    62  
    63  	resp := &s3.PutObjectOutput{}
    64  
    65  	return resp, nil
    66  }