func TestValueAtPathFailure(t *testing.T) { assert.Equal(t, []interface{}(nil), awsutil.ValuesAtPath(data, "C.x")) assert.Equal(t, []interface{}(nil), awsutil.ValuesAtPath(data, ".x")) assert.Equal(t, []interface{}{}, awsutil.ValuesAtPath(data, "X.Y.Z")) assert.Equal(t, []interface{}{}, awsutil.ValuesAtPath(data, "A[100].C")) assert.Equal(t, []interface{}{}, awsutil.ValuesAtPath(data, "A[3].C")) assert.Equal(t, []interface{}{}, awsutil.ValuesAtPath(data, "B.B.C.Z")) assert.Equal(t, []interface{}(nil), awsutil.ValuesAtPath(data, "z[-1].C")) assert.Equal(t, []interface{}{}, awsutil.ValuesAtPath(nil, "A.B.C")) assert.Equal(t, []interface{}{}, awsutil.ValuesAtPath(Struct{}, "A")) }
func TestValueAtPathSuccess(t *testing.T) { assert.Equal(t, []interface{}{"initial"}, awsutil.ValuesAtPath(data, "C")) assert.Equal(t, []interface{}{"value1"}, awsutil.ValuesAtPath(data, "A[0].C")) assert.Equal(t, []interface{}{"value2"}, awsutil.ValuesAtPath(data, "A[1].C")) assert.Equal(t, []interface{}{"value3"}, awsutil.ValuesAtPath(data, "A[2].C")) assert.Equal(t, []interface{}{"value3"}, awsutil.ValuesAtAnyPath(data, "a[2].c")) assert.Equal(t, []interface{}{"value3"}, awsutil.ValuesAtPath(data, "A[-1].C")) assert.Equal(t, []interface{}{"value1", "value2", "value3"}, awsutil.ValuesAtPath(data, "A[].C")) assert.Equal(t, []interface{}{"terminal"}, awsutil.ValuesAtPath(data, "B . B . C")) assert.Equal(t, []interface{}{"terminal", "terminal2"}, awsutil.ValuesAtPath(data, "B.*.C")) assert.Equal(t, []interface{}{"initial"}, awsutil.ValuesAtPath(data, "A.D.X || C")) }
func validateSSERequiresSSL(r *aws.Request) { if r.HTTPRequest.URL.Scheme != "https" { p := awsutil.ValuesAtPath(r.Params, "SSECustomerKey||CopySourceSSECustomerKey") if len(p) > 0 { r.Error = errSSERequiresSSL } } }
func TestNoPopulateLocationConstraintIfClassic(t *testing.T) { s := s3.New(&aws.Config{Region: aws.String("us-east-1")}) req, _ := s.CreateBucketRequest(&s3.CreateBucketInput{ Bucket: aws.String("bucket"), }) err := req.Build() assert.NoError(t, err) assert.Equal(t, 0, len(awsutil.ValuesAtPath(req.Params, "CreateBucketConfiguration.LocationConstraint"))) }
func TestNoPopulateLocationConstraintIfProvided(t *testing.T) { s := s3.New(nil) req, _ := s.CreateBucketRequest(&s3.CreateBucketInput{ Bucket: aws.String("bucket"), CreateBucketConfiguration: &s3.CreateBucketConfiguration{}, }) err := req.Build() assert.NoError(t, err) assert.Equal(t, 0, len(awsutil.ValuesAtPath(req.Params, "CreateBucketConfiguration.LocationConstraint"))) }
func TestPopulateLocationConstraint(t *testing.T) { s := s3.New(nil) in := &s3.CreateBucketInput{ Bucket: aws.String("bucket"), } req, _ := s.CreateBucketRequest(in) err := req.Build() assert.NoError(t, err) assert.Equal(t, "mock-region", awsutil.ValuesAtPath(req.Params, "CreateBucketConfiguration.LocationConstraint")[0]) assert.Nil(t, in.CreateBucketConfiguration) // don't modify original params }
func updateHostWithBucket(r *aws.Request) { b := awsutil.ValuesAtPath(r.Params, "Bucket") if len(b) == 0 { return } if bucket := b[0].(string); bucket != "" && hostStyleBucketName(r, bucket) { r.HTTPRequest.URL.Host = bucket + "." + r.HTTPRequest.URL.Host r.HTTPRequest.URL.Path = strings.Replace(r.HTTPRequest.URL.Path, "/{Bucket}", "", -1) if r.HTTPRequest.URL.Path == "" { r.HTTPRequest.URL.Path = "/" } } }
func TestFillAccountIDWithNilStruct(t *testing.T) { req, _ := svc.ListVaultsRequest(nil) err := req.Build() assert.NoError(t, err) empty := "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" // Sets Account ID v := awsutil.ValuesAtPath(req.Params, "AccountID") assert.Equal(t, "-", v[0]) // Does not set tree hash assert.Equal(t, empty, req.HTTPRequest.Header.Get("x-amz-content-sha256")) assert.Equal(t, "", req.HTTPRequest.Header.Get("x-amz-sha256-tree-hash")) }
func TestCustomizations(t *testing.T) { req, _ := svc.UploadArchiveRequest(&glacier.UploadArchiveInput{ VaultName: aws.String("vault"), Body: payloadBuf, }) err := req.Build() assert.NoError(t, err) // Sets API version assert.Equal(t, req.Service.APIVersion, req.HTTPRequest.Header.Get("x-amz-glacier-version")) // Sets Account ID v := awsutil.ValuesAtPath(req.Params, "AccountID") assert.Equal(t, "-", v[0]) // Computes checksums linear := "68aff0c5a91aa0491752bfb96e3fef33eb74953804f6a2f7b708d5bcefa8ff6b" tree := "154e26c78fd74d0c2c9b3cc4644191619dc4f2cd539ae2a74d5fd07957a3ee6a" assert.Equal(t, linear, req.HTTPRequest.Header.Get("x-amz-content-sha256")) assert.Equal(t, tree, req.HTTPRequest.Header.Get("x-amz-sha256-tree-hash")) }
func val(i interface{}, s string) interface{} { return awsutil.ValuesAtPath(i, s)[0] }