MCPcopy
hub / github.com/minio/minio-go / TestGetBucketLocationRequest

Function TestGetBucketLocationRequest

bucket-cache_test.go:57–275  ·  view source on GitHub ↗

Tests validate http request generation for 'getBucketLocation'.

(t *testing.T)

Source from the content-addressed store, hash-verified

55
56// Tests validate http request generation for 'getBucketLocation'.
57func TestGetBucketLocationRequest(t *testing.T) {
58 // Generates expected http request for getBucketLocation.
59 // Used for asserting with the actual request generated.
60 createExpectedRequest := func(c *Client, bucketName string) (*http.Request, error) {
61 // Set location query.
62 urlValues := make(url.Values)
63 urlValues.Set("location", "")
64
65 // Set get bucket location always as path style.
66 targetURL := *c.endpointURL
67
68 isVirtualStyle := c.isVirtualHostStyleRequest(targetURL, bucketName)
69
70 var urlStr string
71 if isVirtualStyle {
72 urlStr = targetURL.Scheme + "://" + bucketName + "." + targetURL.Host + "/?location"
73 } else {
74 targetURL.Path = path.Join(bucketName, "") + "/"
75 targetURL.RawQuery = urlValues.Encode()
76 urlStr = targetURL.String()
77 }
78
79 // Get a new HTTP request for the method.
80 req, err := http.NewRequest(http.MethodGet, urlStr, nil)
81 if err != nil {
82 return nil, err
83 }
84
85 // Set UserAgent for the request.
86 c.setUserAgent(req)
87
88 // Get credentials from the configured credentials provider.
89 value, err := c.credsProvider.GetWithContext(c.CredContext())
90 if err != nil {
91 return nil, err
92 }
93
94 var (
95 signerType = value.SignerType
96 accessKeyID = value.AccessKeyID
97 secretAccessKey = value.SecretAccessKey
98 sessionToken = value.SessionToken
99 )
100
101 // Custom signer set then override the behavior.
102 if c.overrideSignerType != credentials.SignatureDefault {
103 signerType = c.overrideSignerType
104 }
105
106 // If signerType returned by credentials helper is anonymous,
107 // then do not sign regardless of signerType override.
108 if value.SignerType == credentials.SignatureAnonymous {
109 signerType = credentials.SignatureAnonymous
110 }
111
112 // Set sha256 sum for signature calculation only
113 // with signature version '4'.
114 switch {

Callers

nothing calls this directly

Calls 15

SignV4Function · 0.92
SignV2Function · 0.92
NewStaticV4Function · 0.92
setUserAgentMethod · 0.80
GetWithContextMethod · 0.80
CredContextMethod · 0.80
IsV4Method · 0.80
IsV2Method · 0.80
NewFunction · 0.70
SetMethod · 0.45

Tested by

no test coverage detected