完善生图5.0的功能
This commit is contained in:
1 parent
88a4268d40
commit
678d213f40
31 files changed
+3281
-107
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
@@ -231,7 +232,7 @@ func TestJobsHTTPMapsBillingChargeErrorsAndPublicUsesPublicCreation(t *testing.T
|
||||
h, _ := NewJobsHandler(JobsDependencies{Service: jobs.NewService(store, time.Now), Platform: platform, Public: publicapi.NewAuthenticator(publicapi.Config{APIKeys: "agent-a:secret"}), Builder: &jobBuilderStub{}, Creation: creation}, JobsConfig{})
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, httptest.NewRequest(http.MethodPost, "/api/generations/image", bytes.NewBufferString(`{"prompt":"hello"}`)))
|
||||
if w.Code != 402 || w.Body.String() != "{\"error\":\"生成任务计费失败。\"}\n" {
|
||||
if w.Code != 402 || w.Body.String() != "{\"error\":\"余额不足,请先充值。\"}\n" {
|
||||
t.Fatalf("platform=%d %s", w.Code, w.Body.String())
|
||||
}
|
||||
creation.err = nil
|
||||
@@ -246,13 +247,16 @@ func TestJobsHTTPMapsBillingChargeErrorsAndPublicUsesPublicCreation(t *testing.T
|
||||
|
||||
func TestJobsHTTPMapsAllCreationBillingOutcomesWithoutLeakingErrors(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
err error
|
||||
want int
|
||||
name string
|
||||
err error
|
||||
want int
|
||||
message string
|
||||
}{
|
||||
{name: "insufficient", err: &billing.StatusError{Status: 402, Err: billing.ErrInsufficientBalance}, want: 402},
|
||||
{name: "idempotency", err: &billing.StatusError{Status: 409, Err: billing.ErrIdempotencyConflict}, want: 409},
|
||||
{name: "unknown", err: errors.New("postgres password leaked"), want: 500},
|
||||
{name: "insufficient", err: &billing.StatusError{Status: 402, Err: billing.ErrInsufficientBalance}, want: 402, message: "余额不足,请先充值。"},
|
||||
{name: "organization", err: &billing.StatusError{Status: 409, Err: billing.ErrOrganizationUnavailable}, want: 409, message: "账号未绑定有效组织,请联系管理员。"},
|
||||
{name: "idempotency", err: &billing.StatusError{Status: 409, Err: billing.ErrIdempotencyConflict}, want: 409, message: "生成任务计费失败。"},
|
||||
{name: "unavailable", err: billing.ErrProviderUnavailable, want: 503, message: "计费服务暂不可用,请稍后重试。"},
|
||||
{name: "unknown", err: errors.New("postgres password leaked"), want: 500, message: "Internal server error."},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
@@ -262,7 +266,7 @@ func TestJobsHTTPMapsAllCreationBillingOutcomesWithoutLeakingErrors(t *testing.T
|
||||
h, _ := NewJobsHandler(JobsDependencies{Service: jobs.NewService(store, time.Now), Platform: platform, Public: publicapi.NewAuthenticator(publicapi.Config{APIKeys: "agent-a:secret"}), Builder: &jobBuilderStub{}, Creation: creation}, JobsConfig{})
|
||||
w := httptest.NewRecorder()
|
||||
h.ServeHTTP(w, httptest.NewRequest(http.MethodPost, "/api/generations/image", bytes.NewBufferString(`{"prompt":"hello"}`)))
|
||||
if w.Code != test.want || strings.Contains(w.Body.String(), "postgres") {
|
||||
if w.Code != test.want || w.Body.String() != fmt.Sprintf("{\"error\":%q}\n", test.message) || strings.Contains(w.Body.String(), "postgres") {
|
||||
t.Fatalf("status=%d body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user