- Notifications
You must be signed in to change notification settings - Fork940
feat: Add support for Git tag operations#345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -10,6 +10,15 @@ import ( | ||
"github.com/stretchr/testify/require" | ||
) | ||
// expectPath is a helper function to create a partial mock that expects a | ||
// request with the given path, with the ability to chain a response handler. | ||
func expectPath(t *testing.T, expectedPath string) *partialMock { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I like expect path. I think it will catch both errors matching args into API requests and protect from regressions also. GitHub API is very stable and I don't expect much maintenance will be required. | ||
return &partialMock{ | ||
t: t, | ||
expectedPath: expectedPath, | ||
} | ||
} | ||
// expectQueryParams is a helper function to create a partial mock that expects a | ||
// request with the given query parameters, with the ability to chain a response handler. | ||
func expectQueryParams(t *testing.T, expectedQueryParams map[string]string) *partialMock { | ||
@@ -29,20 +38,18 @@ func expectRequestBody(t *testing.T, expectedRequestBody any) *partialMock { | ||
} | ||
type partialMock struct { | ||
t *testing.T | ||
expectedPath string | ||
expectedQueryParams map[string]string | ||
expectedRequestBody any | ||
} | ||
func (p *partialMock) andThen(responseHandler http.HandlerFunc) http.HandlerFunc { | ||
p.t.Helper() | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
if p.expectedPath != "" { | ||
require.Equal(p.t, p.expectedPath, r.URL.Path) | ||
} | ||
if p.expectedQueryParams != nil { | ||
@@ -52,6 +59,14 @@ func (p *partialMock) andThen(responseHandler http.HandlerFunc) http.HandlerFunc | ||
} | ||
} | ||
if p.expectedRequestBody != nil { | ||
var unmarshaledRequestBody any | ||
err := json.NewDecoder(r.Body).Decode(&unmarshaledRequestBody) | ||
require.NoError(p.t, err) | ||
require.Equal(p.t, p.expectedRequestBody, unmarshaledRequestBody) | ||
} | ||
responseHandler(w, r) | ||
} | ||
} | ||
Uh oh!
There was an error while loading.Please reload this page.