本文整理汇总了Golang中github.com/Azure/azure-sdk-for-go/Godeps/_workspace/src/github.com/Azure/go-autorest/autorest/mocks.NewSender函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSender函数的具体用法?Golang NewSender怎么用?Golang NewSender使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewSender函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: ExampleSendWithSender
func ExampleSendWithSender() {
client := mocks.NewSender()
client.EmitStatus("202 Accepted", http.StatusAccepted)
logger := log.New(os.Stdout, "autorest: ", 0)
na := NullAuthorizer{}
req, _ := Prepare(&http.Request{},
AsGet(),
WithBaseURL("https://microsoft.com/a/b/c/"),
na.WithAuthorization())
r, _ := SendWithSender(client, req,
WithLogging(logger),
DoErrorIfStatusCode(http.StatusAccepted),
DoCloseIfError(),
DoRetryForAttempts(5, time.Duration(0)))
Respond(r,
ByClosing())
// Output:
// autorest: Sending GET https://microsoft.com/a/b/c/
// autorest: GET https://microsoft.com/a/b/c/ received 202 Accepted
// autorest: Sending GET https://microsoft.com/a/b/c/
// autorest: GET https://microsoft.com/a/b/c/ received 202 Accepted
// autorest: Sending GET https://microsoft.com/a/b/c/
// autorest: GET https://microsoft.com/a/b/c/ received 202 Accepted
// autorest: Sending GET https://microsoft.com/a/b/c/
// autorest: GET https://microsoft.com/a/b/c/ received 202 Accepted
// autorest: Sending GET https://microsoft.com/a/b/c/
// autorest: GET https://microsoft.com/a/b/c/ received 202 Accepted
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:33,代码来源:sender_test.go
示例2: TestClientPollAsNeededPollsForDuration
func TestClientPollAsNeededPollsForDuration(t *testing.T) {
c := Client{}
c.PollingMode = PollUntilDuration
c.PollingDuration = 10 * time.Millisecond
s := mocks.NewSender()
s.EmitStatus("202 Accepted", http.StatusAccepted)
c.Sender = s
r := mocks.NewResponseWithStatus("202 Accepted", http.StatusAccepted)
mocks.SetAcceptedHeaders(r)
s.SetResponse(r)
d1 := 10 * time.Millisecond
start := time.Now()
resp, _ := c.PollAsNeeded(r)
d2 := time.Now().Sub(start)
if d2 < d1 {
t.Errorf("autorest: Client#PollAsNeeded did not poll for the expected duration -- expected %v, actual %v",
d1.Seconds(), d2.Seconds())
}
Respond(resp,
ByClosing())
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:25,代码来源:client_test.go
示例3: 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.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) {
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:kbxkb,项目名称:azure-sdk-for-go,代码行数:30,代码来源:token_test.go
示例4: TestAllInstancesResourceGroupNotFound
func (s *environSuite) TestAllInstancesResourceGroupNotFound(c *gc.C) {
env := s.openEnviron(c)
sender := mocks.NewSender()
sender.EmitStatus("resource group not found", http.StatusNotFound)
s.sender = azuretesting.Senders{sender}
_, err := env.AllInstances()
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:makyo,项目名称:juju,代码行数:8,代码来源:environ_test.go
示例5: TestStopInstancesNotFound
func (s *environSuite) TestStopInstancesNotFound(c *gc.C) {
env := s.openEnviron(c)
sender := mocks.NewSender()
sender.EmitStatus("vm not found", http.StatusNotFound)
s.sender = azuretesting.Senders{sender, sender, sender}
err := env.StopInstances("a", "b")
c.Assert(err, jc.ErrorIsNil)
}
开发者ID:makyo,项目名称:juju,代码行数:8,代码来源:environ_test.go
示例6: NewSenderWithValue
// NewSenderWithValue returns a *mocks.Sender that marshals the provided object
// to JSON and sets it as the content. This function will panic if marshalling
// fails.
func NewSenderWithValue(v interface{}) *MockSender {
content, err := json.Marshal(v)
if err != nil {
panic(err)
}
sender := &MockSender{Sender: mocks.NewSender()}
sender.EmitContent(string(content))
return sender
}
开发者ID:imoapps,项目名称:juju,代码行数:12,代码来源:senders.go
示例7: TestServicePrincipalTokenSetSender
func TestServicePrincipalTokenSetSender(t *testing.T) {
spt := newServicePrincipalToken()
var s autorest.Sender
s = mocks.NewSender()
spt.SetSender(s)
if !reflect.DeepEqual(s, spt.sender) {
t.Error("azure: ServicePrincipalToken#SetSender did not set the sender")
}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:10,代码来源:token_test.go
示例8: TestClientSendReturnsPrepareError
func TestClientSendReturnsPrepareError(t *testing.T) {
r := mocks.NewRequest()
s := mocks.NewSender()
c := Client{Authorizer: mockFailingAuthorizer{}, Sender: s}
_, err := c.Send(r)
if err == nil {
t.Error("autorest: Client#Send failed to return an error the Prepare error")
}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:10,代码来源:client_test.go
示例9: TestClientSendSends
func TestClientSendSends(t *testing.T) {
r := mocks.NewRequest()
s := mocks.NewSender()
c := Client{Sender: s}
c.Send(r)
if s.Attempts() <= 0 {
t.Error("autorest: Client#Send failed to invoke the Sender")
}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:10,代码来源:client_test.go
示例10: TestClientSenderReturnsSetSender
func TestClientSenderReturnsSetSender(t *testing.T) {
c := Client{}
s := mocks.NewSender()
c.Sender = s
if c.sender() != s {
t.Error("autorest: Client#sender failed to return set Sender")
}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:10,代码来源:client_test.go
示例11: TestClientDoInvokesSender
func TestClientDoInvokesSender(t *testing.T) {
c := Client{}
s := mocks.NewSender()
c.Sender = s
c.Do(&http.Request{})
if s.Attempts() != 1 {
t.Error("autorest: Client#Do failed to invoke the Sender")
}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:11,代码来源:client_test.go
示例12: TestClientSendInvokesInspector
func TestClientSendInvokesInspector(t *testing.T) {
r := mocks.NewRequest()
s := mocks.NewSender()
i := &mockInspector{}
c := Client{RequestInspector: i.WithInspection(), Sender: s}
c.Send(r)
if !i.wasInvoked {
t.Error("autorest: Client#Send failed to invoke the RequestInspector")
}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:11,代码来源:client_test.go
示例13: TestClientSendDoesNotPollIfUnnecessary
func TestClientSendDoesNotPollIfUnnecessary(t *testing.T) {
r := mocks.NewRequest()
s := mocks.NewSender()
c := Client{Sender: s, PollingMode: PollUntilAttempts, PollingAttempts: 10}
c.Send(r, http.StatusOK, http.StatusAccepted)
if s.Attempts() != 1 {
t.Errorf("autorest: Client#Send unexpectedly polled -- attempts %d",
s.Attempts())
}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:11,代码来源:client_test.go
示例14: TestClientSendReturnsErrorWithUnexpectedStatusCode
func TestClientSendReturnsErrorWithUnexpectedStatusCode(t *testing.T) {
r := mocks.NewRequest()
s := mocks.NewSender()
s.EmitStatus("500 InternalServerError", http.StatusInternalServerError)
c := Client{Sender: s}
_, err := c.Send(r)
if err == nil {
t.Error("autorest: Client#Send failed to return an error for an unexpected Status Code")
}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:11,代码来源:client_test.go
示例15: TestClientSendDefaultsToUsingStatusCodeOK
func TestClientSendDefaultsToUsingStatusCodeOK(t *testing.T) {
r := mocks.NewRequest()
s := mocks.NewSender()
c := Client{Authorizer: mockAuthorizer{}, Sender: s}
_, err := c.Send(r)
if err != nil {
t.Errorf("autorest: Client#Send returned an error for Status Code OK -- %v",
err)
}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:11,代码来源:client_test.go
示例16: TestClientSendClosesReponseBodyWhenReturningError
func TestClientSendClosesReponseBodyWhenReturningError(t *testing.T) {
s := mocks.NewSender()
r := mocks.NewResponseWithStatus("500 InternalServerError", http.StatusInternalServerError)
s.SetResponse(r)
c := Client{Sender: s}
c.Send(mocks.NewRequest())
if r.Body.(*mocks.Body).IsOpen() {
t.Error("autorest: Client#Send failed to close the response body when returning an error")
}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:11,代码来源:client_test.go
示例17: TestServicePrincipalTokenRefreshReturnsErrorIfNotOk
func TestServicePrincipalTokenRefreshReturnsErrorIfNotOk(t *testing.T) {
spt := newServicePrincipalToken()
c := mocks.NewSender()
c.EmitStatus("401 NotAuthorized", 401)
spt.SetSender(c)
err := spt.Refresh()
if err == nil {
t.Error("azure: Failed to return an when receiving a status code other than HTTP 200")
}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:12,代码来源:token_test.go
示例18: TestClientSendPollsIfNeeded
func TestClientSendPollsIfNeeded(t *testing.T) {
r := mocks.NewRequest()
s := mocks.NewSender()
s.SetPollAttempts(5)
c := Client{Sender: s, PollingMode: PollUntilAttempts, PollingAttempts: 10}
c.Send(r, http.StatusOK, http.StatusAccepted)
if s.Attempts() != (5 + 1) {
t.Errorf("autorest: Client#Send failed to poll the expected number of times -- attempts %d",
s.Attempts())
}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:12,代码来源:client_test.go
示例19: TestClientSendDoesNotReturnErrorForExpectedStatusCode
func TestClientSendDoesNotReturnErrorForExpectedStatusCode(t *testing.T) {
r := mocks.NewRequest()
s := mocks.NewSender()
s.EmitStatus("500 InternalServerError", http.StatusInternalServerError)
c := Client{Sender: s}
_, err := c.Send(r, http.StatusInternalServerError)
if err != nil {
t.Errorf("autorest: Client#Send returned an error for an expected Status Code -- %v",
err)
}
}
开发者ID:kbxkb,项目名称:azure-sdk-for-go,代码行数:12,代码来源:client_test.go
示例20: testLocationManagementURI
func (s *environSuite) testLocationManagementURI(c *gc.C, location, host string) {
env := s.openEnviron(c, testing.Attrs{"location": location})
sender := mocks.NewSender()
sender.EmitContent("{}")
s.sender = azuretesting.Senders{sender}
s.requests = nil
env.AllInstances() // trigger a query
c.Assert(s.requests, gc.HasLen, 1)
c.Assert(s.requests[0].URL.Host, gc.Equals, host)
}
开发者ID:pmatulis,项目名称:juju,代码行数:12,代码来源:environ_test.go
注:本文中的github.com/Azure/azure-sdk-for-go/Godeps/_workspace/src/github.com/Azure/go-autorest/autorest/mocks.NewSender函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论