-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02ba493
commit 64a20b1
Showing
8 changed files
with
95 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module github.com/carlmjohnson/requests | ||
|
||
go 1.22 | ||
go 1.23 | ||
|
||
require golang.org/x/net v0.33.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package reqtest | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/carlmjohnson/requests" | ||
) | ||
|
||
// RecorderMode is an argument type controlling [Recorder]. | ||
type RecorderMode int8 | ||
|
||
//go:generate stringer -type=RecorderMode | ||
|
||
// Enum values for type RecorderMode | ||
const ( | ||
// Record HTTP requests and responses to text files. | ||
ModeRecord RecorderMode = iota | ||
// Replay responses from pre-recorded text files. | ||
ModeReplay | ||
// Replay responses from pre-recorded files if present, | ||
// otherwise record a new request response pair. | ||
ModeCache | ||
) | ||
|
||
// Recorder returns an HTTP transport that operates in the specified mode. | ||
// Requests and responses are read from or written to | ||
// text files in basepath according to a hash of their contents. | ||
// File names may optionally be prefixed with comments for better human organization. | ||
// The http.RoundTripper is only used in ModeRecord and ModeCache | ||
// and if nil defaults to http.DefaultTransport. | ||
func Recorder(mode RecorderMode, rt http.RoundTripper, basepath string) requests.Transport { | ||
switch mode { | ||
case ModeReplay: | ||
return Replay(basepath) | ||
case ModeRecord: | ||
return Record(rt, basepath) | ||
case ModeCache: | ||
return Caching(rt, basepath) | ||
default: | ||
panic("invalid reqtest.RecorderMode") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters