本文整理汇总了Golang中github.com/Azure/go-autorest/autorest.DecorateSender函数的典型用法代码示例。如果您正苦于以下问题:Golang DecorateSender函数的具体用法?Golang DecorateSender怎么用?Golang DecorateSender使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DecorateSender函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestServicePrincipalTokenRefreshUsesPOST
func TestServicePrincipalTokenRefreshUsesPOST(t *testing.T) {
spt := newServicePrincipalToken()
body := mocks.NewBody("")
resp := mocks.NewResponseWithBodyAndStatus(body, 200, "OK")
c := mocks.NewSender()
s := autorest.DecorateSender(c,
(func() autorest.SendDecorator {
return func(s autorest.Sender) autorest.Sender {
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
if r.Method != "POST" {
t.Fatalf("azure: ServicePrincipalToken#Refresh did not correctly set HTTP method -- expected %v, received %v", "POST", r.Method)
}
return resp, nil
})
}
})())
spt.SetSender(s)
spt.Refresh()
if body.IsOpen() {
t.Fatalf("the response was not closed!")
}
}
开发者ID:garimakhulbe,项目名称:go-autorest,代码行数:25,代码来源:token_test.go
示例2: TestServicePrincipalTokenRefreshUnmarshals
func TestServicePrincipalTokenRefreshUnmarshals(t *testing.T) {
spt := newServicePrincipalToken()
expiresOn := strconv.Itoa(int(time.Now().Add(3600 * time.Second).Sub(expirationBase).Seconds()))
j := newTokenJSON(expiresOn, "resource")
resp := mocks.NewResponseWithContent(j)
c := mocks.NewClient()
s := autorest.DecorateSender(c,
(func() autorest.SendDecorator {
return func(s autorest.Sender) autorest.Sender {
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
return resp, nil
})
}
})())
spt.SetSender(s)
err := spt.Refresh()
if err != nil {
t.Errorf("azure: ServicePrincipalToken#Refresh returned an unexpected error (%v)", err)
} else if spt.AccessToken != "accessToken" ||
spt.ExpiresIn != "3600" ||
spt.ExpiresOn != expiresOn ||
spt.NotBefore != expiresOn ||
spt.Resource != "resource" ||
spt.Type != "Bearer" {
t.Errorf("azure: ServicePrincipalToken#Refresh failed correctly unmarshal the JSON -- expected %v, received %v",
j, *spt)
}
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:30,代码来源:token_test.go
示例3: TestServicePrincipalTokenRefreshUsesPOST
func TestServicePrincipalTokenRefreshUsesPOST(t *testing.T) {
spt := newServicePrincipalToken()
c := mocks.NewClient()
s := autorest.DecorateSender(c,
(func() autorest.SendDecorator {
return func(s autorest.Sender) autorest.Sender {
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
if r.Method != "POST" {
t.Errorf("azure: ServicePrincipalToken#Refresh did not correctly set HTTP method -- expected %v, received %v", "POST", r.Method)
}
return mocks.NewResponse(), nil
})
}
})())
spt.SetSender(s)
spt.Refresh()
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:18,代码来源:token_test.go
示例4: testServicePrincipalTokenRefreshSetsBody
func testServicePrincipalTokenRefreshSetsBody(t *testing.T, spt *ServicePrincipalToken, f func(*testing.T, []byte)) {
c := mocks.NewSender()
s := autorest.DecorateSender(c,
(func() autorest.SendDecorator {
return func(s autorest.Sender) autorest.Sender {
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Fatalf("azure: Failed to read body of Service Principal token request (%v)", err)
}
f(t, b)
return mocks.NewResponse(), nil
})
}
})())
spt.SetSender(s)
spt.Refresh()
}
开发者ID:garimakhulbe,项目名称:go-autorest,代码行数:18,代码来源:token_test.go
示例5: TestServicePrincipalTokenRefreshSetsURL
func TestServicePrincipalTokenRefreshSetsURL(t *testing.T) {
spt := newServicePrincipalToken()
c := mocks.NewSender()
s := autorest.DecorateSender(c,
(func() autorest.SendDecorator {
return func(s autorest.Sender) autorest.Sender {
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
if r.URL.String() != TestOAuthConfig.TokenEndpoint.String() {
t.Fatalf("azure: ServicePrincipalToken#Refresh did not correctly set the URL -- expected %v, received %v",
TestOAuthConfig.TokenEndpoint, r.URL)
}
return mocks.NewResponse(), nil
})
}
})())
spt.SetSender(s)
spt.Refresh()
}
开发者ID:garimakhulbe,项目名称:go-autorest,代码行数:19,代码来源:token_test.go
示例6: TestServicePrincipalTokenRefreshClosesRequestBody
func TestServicePrincipalTokenRefreshClosesRequestBody(t *testing.T) {
spt := newServicePrincipalToken()
resp := mocks.NewResponse()
c := mocks.NewClient()
s := autorest.DecorateSender(c,
(func() autorest.SendDecorator {
return func(s autorest.Sender) autorest.Sender {
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
return resp, nil
})
}
})())
spt.SetSender(s)
spt.Refresh()
if resp.Body.(*mocks.Body).IsOpen() {
t.Error("azure: ServicePrincipalToken#Refresh failed to close the HTTP Response Body")
}
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:20,代码来源:token_test.go
示例7: TestServicePrincipalTokenRefreshSetsURL
func TestServicePrincipalTokenRefreshSetsURL(t *testing.T) {
spt := newServicePrincipalToken()
c := mocks.NewClient()
s := autorest.DecorateSender(c,
(func() autorest.SendDecorator {
return func(s autorest.Sender) autorest.Sender {
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
u := fmt.Sprintf("https://login.microsoftonline.com/%s/oauth2/token?api-version=1.0", spt.tenantId)
if r.URL.String() != u {
t.Errorf("azure: ServicePrincipalToken#Refresh did not correctly set the URL -- expected %v, received %v",
u, r.URL)
}
return mocks.NewResponse(), nil
})
}
})())
spt.SetSender(s)
spt.Refresh()
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:20,代码来源:token_test.go
示例8: TestServicePrincipalTokenRefreshSetsMimeType
func TestServicePrincipalTokenRefreshSetsMimeType(t *testing.T) {
spt := newServicePrincipalToken()
c := mocks.NewClient()
s := autorest.DecorateSender(c,
(func() autorest.SendDecorator {
return func(s autorest.Sender) autorest.Sender {
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
if r.Header.Get(http.CanonicalHeaderKey("Content-Type")) != "application/x-www-form-urlencoded" {
t.Errorf("azure: ServicePrincipalToken#Refresh did not correctly set Content-Type -- expected %v, received %v",
"application/x-form-urlencoded",
r.Header.Get(http.CanonicalHeaderKey("Content-Type")))
}
return mocks.NewResponse(), nil
})
}
})())
spt.SetSender(s)
spt.Refresh()
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:20,代码来源:token_test.go
示例9: TestServicePrincipalTokenEnsureFreshSkipsIfFresh
func TestServicePrincipalTokenEnsureFreshSkipsIfFresh(t *testing.T) {
spt := newServicePrincipalToken()
setTokenToExpireIn(&spt.Token, 1000*time.Second)
f := false
c := mocks.NewSender()
s := autorest.DecorateSender(c,
(func() autorest.SendDecorator {
return func(s autorest.Sender) autorest.Sender {
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
f = true
return mocks.NewResponse(), nil
})
}
})())
spt.SetSender(s)
spt.EnsureFresh()
if f {
t.Fatal("azure: ServicePrincipalToken#EnsureFresh invoked Refresh for fresh token")
}
}
开发者ID:garimakhulbe,项目名称:go-autorest,代码行数:21,代码来源:token_test.go
示例10: TestServicePrincipalTokenEnsureFreshRefreshes
func TestServicePrincipalTokenEnsureFreshRefreshes(t *testing.T) {
spt := newServicePrincipalToken()
expireToken(&spt.Token)
f := false
c := mocks.NewSender()
s := autorest.DecorateSender(c,
(func() autorest.SendDecorator {
return func(s autorest.Sender) autorest.Sender {
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
f = true
return mocks.NewResponse(), nil
})
}
})())
spt.SetSender(s)
spt.EnsureFresh()
if !f {
t.Fatal("azure: ServicePrincipalToken#EnsureFresh failed to call Refresh for stale token")
}
}
开发者ID:garimakhulbe,项目名称:go-autorest,代码行数:21,代码来源:token_test.go
示例11: TestServicePrincipalTokenRefreshSetsBody
func TestServicePrincipalTokenRefreshSetsBody(t *testing.T) {
spt := newServicePrincipalToken()
c := mocks.NewClient()
s := autorest.DecorateSender(c,
(func() autorest.SendDecorator {
return func(s autorest.Sender) autorest.Sender {
return autorest.SenderFunc(func(r *http.Request) (*http.Response, error) {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Errorf("azure: Failed to read body of Service Principal token request (%v)", err)
} else if string(b) != defaultFormData {
t.Errorf("azure: ServicePrincipalToken#Refresh did not correctly set the HTTP Request Body -- expected %v, received %v",
defaultFormData, string(b))
}
return mocks.NewResponse(), nil
})
}
})())
spt.SetSender(s)
spt.Refresh()
}
开发者ID:oaastest,项目名称:go-autorest,代码行数:22,代码来源:token_test.go
注:本文中的github.com/Azure/go-autorest/autorest.DecorateSender函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论