feat(tools): branch_delete
This commit is contained in:
@@ -138,3 +138,29 @@ func TestUpsertFileSendsPayloadAndDecodesResult(t *testing.T) {
|
||||
assert.Equal(t, "http://example.com/p.md", result.Content.HTMLURL)
|
||||
assert.Equal(t, "abc", result.Commit.Sha)
|
||||
}
|
||||
|
||||
func TestDeleteBranch(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
assert.Equal(t, "/api/v1/repos/o/r/branches/feat/x", r.URL.Path)
|
||||
assert.Equal(t, http.MethodDelete, r.Method)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
c := gitea.NewClient(srv.URL, "tok")
|
||||
err := c.DeleteBranch(context.Background(), "o", "r", "feat/x")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestDeleteBranchProtected(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
_, _ = w.Write([]byte(`{"message":"branch is protected"}`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
c := gitea.NewClient(srv.URL, "tok")
|
||||
err := c.DeleteBranch(context.Background(), "o", "r", "main")
|
||||
require.Error(t, err)
|
||||
assert.ErrorIs(t, err, gitea.ErrPermissionDenied)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user