feat(workspace): add GET /branches endpoint

This commit is contained in:
2026-06-10 18:07:13 +08:00
parent 665d029d2b
commit 12ba5d5365
3 changed files with 48 additions and 1 deletions
+24 -1
View File
@@ -49,7 +49,7 @@ func (f *fakeWS) GetCredentialMeta(_ context.Context, _ Caller, _ uuid.UUID) (*C
}
func (f *fakeWS) ListBranches(_ context.Context, _ Caller, _ uuid.UUID) ([]string, error) {
return nil, nil
return []string{"main", "develop"}, nil
}
// fakeResolver 把固定 token 解码为 uuid(沿 internal/project handler_test.go 模式)。
@@ -86,3 +86,26 @@ func TestHandler_CreateWorkspace_Smoke(t *testing.T) {
r.ServeHTTP(w, req)
require.Equal(t, http.StatusCreated, w.Code)
}
func TestHandler_ListBranches_Smoke(t *testing.T) {
t.Parallel()
ws := &fakeWS{}
uid := uuid.New()
tok := "tok-branches"
resolver := &fakeResolver{valid: map[string]uuid.UUID{tok: uid}}
h := NewHandler(ws, nil, nil, resolver, fakeAdmin{})
r := chi.NewRouter()
r.Use(middleware.RequestID)
h.Mount(r)
wsID := uuid.New()
req := httptest.NewRequest("GET", "/api/v1/workspaces/"+wsID.String()+"/branches", nil)
req.Header.Set("Authorization", "Bearer "+tok)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
require.Equal(t, http.StatusOK, w.Code)
var resp branchListResp
require.NoError(t, json.NewDecoder(w.Body).Decode(&resp))
require.Equal(t, []string{"main", "develop"}, resp.Branches)
}