feat: complete remaining Go backend modules
This commit is contained in:
1 parent
cea2751dc5
commit
aef5a97165
145 files changed
+18376
-199
No files matched your search
@@ -0,0 +1,49 @@
|
||||
package orchestration
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/billing"
|
||||
"git.nianxx.cn/wangxuming/NianAIGC/backend/internal/jobs"
|
||||
)
|
||||
|
||||
func TestCreationCoordinatorDoesNotFailCreationWhenAtomicCommitOutcomeIsUnknown(t *testing.T) {
|
||||
state := &commitUnknownCreationState{}
|
||||
coordinator := &CreationCoordinator{charges: &chargeLedgerStub{}, state: state}
|
||||
job := jobs.Job{
|
||||
ID: "job-1",
|
||||
Capability: "image.generate",
|
||||
ReqKey: "wanx",
|
||||
Billing: json.RawMessage(`{"status":"pending","amountFen":35}`),
|
||||
UsageContext: json.RawMessage(`{"accountId":"account","organizationId":"org"}`),
|
||||
}
|
||||
|
||||
_, _, err := coordinator.charge(context.Background(), job, false)
|
||||
if err == nil || err.Error() != "charge generation job" {
|
||||
t.Fatalf("err=%v, want generic infrastructure error", err)
|
||||
}
|
||||
if state.failCalls != 0 {
|
||||
t.Fatalf("FailCreation calls=%d, want 0", state.failCalls)
|
||||
}
|
||||
}
|
||||
|
||||
type commitUnknownCreationState struct {
|
||||
failCalls int
|
||||
}
|
||||
|
||||
func (*commitUnknownCreationState) ChargeAndActivateCreation(context.Context, billing.ChargeRequest, json.RawMessage) (json.RawMessage, error) {
|
||||
return nil, errors.Join(errors.New("commit response and reconciliation failed"), billing.ErrCommitOutcomeUnknown)
|
||||
}
|
||||
func (*commitUnknownCreationState) WriteBilling(context.Context, string, json.RawMessage) error {
|
||||
return nil
|
||||
}
|
||||
func (*commitUnknownCreationState) ActivateCreation(context.Context, string, json.RawMessage) error {
|
||||
return nil
|
||||
}
|
||||
func (s *commitUnknownCreationState) FailCreation(context.Context, jobs.Job) error {
|
||||
s.failCalls++
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user