Skip to content

Commit

Permalink
Some refactoring of the fakes package (Azure#20831)
Browse files Browse the repository at this point in the history
* Some refactoring of the fakes package

Deeper testing uncovered some deficiencies as well as general API
improvements like slight renaming and adding options types.
Marshalling APIs (used by fake server) now take an any type instead of a
Responder[T] in order to handle cases where we marshal from a scalar.
Added support for binary, text, and XML formats (binary was halfway
there already, supporting form and multipart but not vanilla).
Added support for specifying an HTTP status code in a fake response.
Added and cleaned up various doc comments.

* fix doc comment

* MarshalResponseAsText takes param by pointer

* remove empty string from MarshalResponseAsText

* renamed AddNonTerminalError to AddPollingError to clarify its behavior

removed HTTP status values from SetReponseOptions as this will be
handled by the generated fake servers.
don't panic on nil request bodies.

* add support for byte arrays

* merge NewBinaryResponse into NewResponse with optional body params
  • Loading branch information
jhendrixMSFT authored May 16, 2023
1 parent 6879d7e commit bda7ac8
Show file tree
Hide file tree
Showing 8 changed files with 459 additions and 93 deletions.
8 changes: 4 additions & 4 deletions sdk/azcore/fake/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func ExampleResponder() {
resp := fake.Responder[WidgetResponse]{}

// here we set the instance of Widget the Responder is to return
resp.Set(WidgetResponse{
resp.SetResponse(WidgetResponse{
Widget{ID: 123, Shape: "triangle"},
})
}, nil)

// optional HTTP headers can also be included in the raw response
resp.SetHeader("custom-header1", "value1")
Expand Down Expand Up @@ -119,7 +119,7 @@ func ExamplePollerResponder() {

// non-terminal errors can also be included in the sequence of responses.
// use this to simulate an error during polling.
pollerResp.AddNonTerminalError(errors.New("flaky network"))
pollerResp.AddPollingError(errors.New("flaky network"))

// use SetTerminalResponse to successfully terminate the long-running operation.
// the provided value will be returned as the terminal response.
Expand All @@ -128,7 +128,7 @@ func ExamplePollerResponder() {
ID: 987,
Shape: "dodecahedron",
},
})
}, nil)
}

func ExamplePollerResponder_SetTerminalError() {
Expand Down
Loading

0 comments on commit bda7ac8

Please sign in to comment.