-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace
FakeHTTP
with httpmock which is now compatible
- Loading branch information
Showing
12 changed files
with
181 additions
and
210 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 was deleted.
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
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
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
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,89 @@ | ||
package httpmock | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"path" | ||
"strings" | ||
) | ||
|
||
// TODO: clean up methods in this file when there are no more callers | ||
|
||
func (r *Registry) StubResponse(status int, body io.Reader) { | ||
r.Register(MatchAny, func(*http.Request) (*http.Response, error) { | ||
return httpResponse(status, body), nil | ||
}) | ||
} | ||
|
||
func (r *Registry) StubWithFixture(status int, fixtureFileName string) func() { | ||
fixturePath := path.Join("../test/fixtures/", fixtureFileName) | ||
fixtureFile, err := os.Open(fixturePath) | ||
r.Register(MatchAny, func(*http.Request) (*http.Response, error) { | ||
if err != nil { | ||
return nil, err | ||
} | ||
return httpResponse(200, fixtureFile), nil | ||
}) | ||
return func() { | ||
if err == nil { | ||
fixtureFile.Close() | ||
} | ||
} | ||
} | ||
|
||
func (r *Registry) StubRepoResponse(owner, repo string) { | ||
r.StubRepoResponseWithPermission(owner, repo, "WRITE") | ||
} | ||
|
||
func (r *Registry) StubRepoResponseWithPermission(owner, repo, permission string) { | ||
r.Register(MatchAny, StringResponse(RepoNetworkStubResponse(owner, repo, "master", permission))) | ||
} | ||
|
||
func (r *Registry) StubRepoResponseWithDefaultBranch(owner, repo, defaultBranch string) { | ||
r.Register(MatchAny, StringResponse(RepoNetworkStubResponse(owner, repo, defaultBranch, "WRITE"))) | ||
} | ||
|
||
func (r *Registry) StubForkedRepoResponse(ownRepo, parentRepo string) { | ||
r.Register(MatchAny, StringResponse(RepoNetworkStubForkResponse(ownRepo, parentRepo))) | ||
} | ||
|
||
func RepoNetworkStubResponse(owner, repo, defaultBranch, permission string) string { | ||
return fmt.Sprintf(` | ||
{ "data": { "repo_000": { | ||
"id": "REPOID", | ||
"name": "%s", | ||
"owner": {"login": "%s"}, | ||
"defaultBranchRef": { | ||
"name": "%s" | ||
}, | ||
"viewerPermission": "%s" | ||
} } } | ||
`, repo, owner, defaultBranch, permission) | ||
} | ||
|
||
func RepoNetworkStubForkResponse(forkFullName, parentFullName string) string { | ||
forkRepo := strings.SplitN(forkFullName, "/", 2) | ||
parentRepo := strings.SplitN(parentFullName, "/", 2) | ||
return fmt.Sprintf(` | ||
{ "data": { "repo_000": { | ||
"id": "REPOID2", | ||
"name": "%s", | ||
"owner": {"login": "%s"}, | ||
"defaultBranchRef": { | ||
"name": "master" | ||
}, | ||
"viewerPermission": "ADMIN", | ||
"parent": { | ||
"id": "REPOID1", | ||
"name": "%s", | ||
"owner": {"login": "%s"}, | ||
"defaultBranchRef": { | ||
"name": "master" | ||
}, | ||
"viewerPermission": "READ" | ||
} | ||
} } } | ||
`, forkRepo[1], forkRepo[0], parentRepo[1], parentRepo[0]) | ||
} |
Oops, something went wrong.