修复 Context 改造后的编译问题
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
// TestServiceDependencyChecks 测试 Service 依赖检查
|
||||
func TestServiceStartWithNilRepo(t *testing.T) {
|
||||
svc := &Service{repo: nil}
|
||||
_, err := svc.Start(1, 100, StartPaymentRequest{}, "127.0.0.1")
|
||||
_, err := svc.Start(t.Context(), 1, 100, StartPaymentRequest{}, "127.0.0.1")
|
||||
if !errors.Is(err, ErrDependencyUnavailable) {
|
||||
t.Fatalf("Start() error = %v, want ErrDependencyUnavailable", err)
|
||||
}
|
||||
@@ -18,13 +18,13 @@ func TestServiceStartWithInvalidParams(t *testing.T) {
|
||||
svc := &Service{repo: &Repository{}}
|
||||
|
||||
// 测试 userID 为 0
|
||||
_, err := svc.Start(0, 100, StartPaymentRequest{}, "127.0.0.1")
|
||||
_, err := svc.Start(t.Context(), 0, 100, StartPaymentRequest{}, "127.0.0.1")
|
||||
if !errors.Is(err, ErrPaymentCannotStart) {
|
||||
t.Fatalf("Start() error = %v, want ErrPaymentCannotStart", err)
|
||||
}
|
||||
|
||||
// 测试 orderID 为 0
|
||||
_, err = svc.Start(1, 0, StartPaymentRequest{}, "127.0.0.1")
|
||||
_, err = svc.Start(t.Context(), 1, 0, StartPaymentRequest{}, "127.0.0.1")
|
||||
if !errors.Is(err, ErrPaymentCannotStart) {
|
||||
t.Fatalf("Start() error = %v, want ErrPaymentCannotStart", err)
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func TestServiceStartWithInvalidParams(t *testing.T) {
|
||||
|
||||
func TestServiceQueryWithNilRepo(t *testing.T) {
|
||||
svc := &Service{repo: nil}
|
||||
_, err := svc.Query(1, 100)
|
||||
_, err := svc.Query(t.Context(), 1, 100)
|
||||
if !errors.Is(err, ErrDependencyUnavailable) {
|
||||
t.Fatalf("Query() error = %v, want ErrDependencyUnavailable", err)
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func TestServiceQueryWithNilRepo(t *testing.T) {
|
||||
func TestServiceQueryWithInvalidParams(t *testing.T) {
|
||||
svc := &Service{repo: &Repository{}}
|
||||
|
||||
_, err := svc.Query(0, 100)
|
||||
_, err := svc.Query(t.Context(), 0, 100)
|
||||
if !errors.Is(err, ErrPaymentNotFound) {
|
||||
t.Fatalf("Query() error = %v, want ErrPaymentNotFound", err)
|
||||
}
|
||||
@@ -49,7 +49,7 @@ func TestServiceQueryWithInvalidParams(t *testing.T) {
|
||||
|
||||
func TestServiceStartRefundWithNilRepo(t *testing.T) {
|
||||
svc := &Service{repo: nil}
|
||||
_, err := svc.StartRefund(100, 1000, "cancel_refund", "test")
|
||||
_, err := svc.StartRefund(t.Context(), 100, 1000, "cancel_refund", "test")
|
||||
if !errors.Is(err, ErrDependencyUnavailable) {
|
||||
t.Fatalf("StartRefund() error = %v, want ErrDependencyUnavailable", err)
|
||||
}
|
||||
@@ -59,13 +59,13 @@ func TestServiceStartRefundWithInvalidParams(t *testing.T) {
|
||||
svc := &Service{repo: &Repository{}}
|
||||
|
||||
// 测试 orderID 为 0
|
||||
_, err := svc.StartRefund(0, 1000, "cancel_refund", "test")
|
||||
_, err := svc.StartRefund(t.Context(), 0, 1000, "cancel_refund", "test")
|
||||
if !errors.Is(err, ErrRefundCannotStart) {
|
||||
t.Fatalf("StartRefund() error = %v, want ErrRefundCannotStart", err)
|
||||
}
|
||||
|
||||
// 测试金额为 0
|
||||
_, err = svc.StartRefund(100, 0, "cancel_refund", "test")
|
||||
_, err = svc.StartRefund(t.Context(), 100, 0, "cancel_refund", "test")
|
||||
if !errors.Is(err, ErrRefundCannotStart) {
|
||||
t.Fatalf("StartRefund() error = %v, want ErrRefundCannotStart", err)
|
||||
}
|
||||
@@ -73,7 +73,7 @@ func TestServiceStartRefundWithInvalidParams(t *testing.T) {
|
||||
|
||||
func TestServiceWalletRechargeDisabledInProduction(t *testing.T) {
|
||||
svc := NewService(&Repository{}, "production")
|
||||
_, err := svc.StartWalletRecharge(1, WalletRechargePaymentRequest{AmountCent: 1000}, "127.0.0.1")
|
||||
_, err := svc.StartWalletRecharge(t.Context(), 1, WalletRechargePaymentRequest{AmountCent: 1000}, "127.0.0.1")
|
||||
if !errors.Is(err, ErrWalletRechargeDisabled) {
|
||||
t.Fatalf("StartWalletRecharge() error = %v, want ErrWalletRechargeDisabled", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user