继续补齐核心模块 Context 超时控制
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
// TestServiceDependencyChecks 测试所有 Service 方法的依赖检查
|
||||
func TestServiceCreateWithNilRepo(t *testing.T) {
|
||||
svc := &Service{repo: nil}
|
||||
_, err := svc.Create(1, CreateRequest{ListingID: 100})
|
||||
_, err := svc.Create(t.Context(), 1, CreateRequest{ListingID: 100})
|
||||
if !errors.Is(err, ErrDependencyUnavailable) {
|
||||
t.Fatalf("Create() error = %v, want ErrDependencyUnavailable", err)
|
||||
}
|
||||
@@ -16,7 +16,7 @@ func TestServiceCreateWithNilRepo(t *testing.T) {
|
||||
|
||||
func TestServiceCreateWithZeroListingID(t *testing.T) {
|
||||
svc := &Service{repo: &Repository{}}
|
||||
_, err := svc.Create(1, CreateRequest{ListingID: 0})
|
||||
_, err := svc.Create(t.Context(), 1, CreateRequest{ListingID: 0})
|
||||
if !errors.Is(err, ErrInvalidRentHours) {
|
||||
t.Fatalf("Create() error = %v, want ErrInvalidRentHours", err)
|
||||
}
|
||||
@@ -24,7 +24,7 @@ func TestServiceCreateWithZeroListingID(t *testing.T) {
|
||||
|
||||
func TestServiceCancelWithNilRepo(t *testing.T) {
|
||||
svc := &Service{repo: nil}
|
||||
err := svc.Cancel(1, 100)
|
||||
err := svc.Cancel(t.Context(), 1, 100)
|
||||
if !errors.Is(err, ErrDependencyUnavailable) {
|
||||
t.Fatalf("Cancel() error = %v, want ErrDependencyUnavailable", err)
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func TestServiceCancelWithNilRepo(t *testing.T) {
|
||||
|
||||
func TestServicePayWithNilRepo(t *testing.T) {
|
||||
svc := &Service{repo: nil}
|
||||
err := svc.Pay(1, 100)
|
||||
err := svc.Pay(t.Context(), 1, 100)
|
||||
if !errors.Is(err, ErrDependencyUnavailable) {
|
||||
t.Fatalf("Pay() error = %v, want ErrDependencyUnavailable", err)
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func TestServicePayWithNilRepo(t *testing.T) {
|
||||
|
||||
func TestServicePayWithZeroOrderID(t *testing.T) {
|
||||
svc := &Service{repo: &Repository{}}
|
||||
err := svc.Pay(1, 0)
|
||||
err := svc.Pay(t.Context(), 1, 0)
|
||||
if !errors.Is(err, ErrOrderCannotPay) {
|
||||
t.Fatalf("Pay() error = %v, want ErrOrderCannotPay", err)
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func TestServicePayWithZeroOrderID(t *testing.T) {
|
||||
|
||||
func TestServiceSubmitHandoffWithNilRepo(t *testing.T) {
|
||||
svc := &Service{repo: nil}
|
||||
_, err := svc.SubmitHandoff(1, 100, SubmitHandoffRequest{Content: "test"})
|
||||
_, err := svc.SubmitHandoff(t.Context(), 1, 100, SubmitHandoffRequest{Content: "test"})
|
||||
if !errors.Is(err, ErrDependencyUnavailable) {
|
||||
t.Fatalf("SubmitHandoff() error = %v, want ErrDependencyUnavailable", err)
|
||||
}
|
||||
@@ -56,7 +56,7 @@ func TestServiceSubmitHandoffWithNilRepo(t *testing.T) {
|
||||
|
||||
func TestServiceSubmitHandoffWithEmptyContent(t *testing.T) {
|
||||
svc := &Service{repo: &Repository{}}
|
||||
_, err := svc.SubmitHandoff(1, 100, SubmitHandoffRequest{Content: ""})
|
||||
_, err := svc.SubmitHandoff(t.Context(), 1, 100, SubmitHandoffRequest{Content: ""})
|
||||
if !errors.Is(err, ErrOrderCannotHandoff) {
|
||||
t.Fatalf("SubmitHandoff() error = %v, want ErrOrderCannotHandoff", err)
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func TestServiceSubmitHandoffWithEmptyContent(t *testing.T) {
|
||||
|
||||
func TestServiceConfirmReceiveWithNilRepo(t *testing.T) {
|
||||
svc := &Service{repo: nil}
|
||||
err := svc.ConfirmReceive(1, 100)
|
||||
err := svc.ConfirmReceive(t.Context(), 1, 100)
|
||||
if !errors.Is(err, ErrDependencyUnavailable) {
|
||||
t.Fatalf("ConfirmReceive() error = %v, want ErrDependencyUnavailable", err)
|
||||
}
|
||||
@@ -72,7 +72,7 @@ func TestServiceConfirmReceiveWithNilRepo(t *testing.T) {
|
||||
|
||||
func TestServiceSubmitReturnWithNilRepo(t *testing.T) {
|
||||
svc := &Service{repo: nil}
|
||||
_, err := svc.SubmitReturn(1, 100, SubmitReturnRequest{Content: "test"})
|
||||
_, err := svc.SubmitReturn(t.Context(), 1, 100, SubmitReturnRequest{Content: "test"})
|
||||
if !errors.Is(err, ErrDependencyUnavailable) {
|
||||
t.Fatalf("SubmitReturn() error = %v, want ErrDependencyUnavailable", err)
|
||||
}
|
||||
@@ -80,7 +80,7 @@ func TestServiceSubmitReturnWithNilRepo(t *testing.T) {
|
||||
|
||||
func TestServiceSubmitReturnWithEmptyContent(t *testing.T) {
|
||||
svc := &Service{repo: &Repository{}}
|
||||
_, err := svc.SubmitReturn(1, 100, SubmitReturnRequest{Content: ""})
|
||||
_, err := svc.SubmitReturn(t.Context(), 1, 100, SubmitReturnRequest{Content: ""})
|
||||
if !errors.Is(err, ErrOrderCannotReturn) {
|
||||
t.Fatalf("SubmitReturn() error = %v, want ErrOrderCannotReturn", err)
|
||||
}
|
||||
@@ -88,7 +88,7 @@ func TestServiceSubmitReturnWithEmptyContent(t *testing.T) {
|
||||
|
||||
func TestServiceSubmitCheckoutWithNilRepo(t *testing.T) {
|
||||
svc := &Service{repo: nil}
|
||||
_, err := svc.SubmitCheckout(1, 100, SubmitCheckoutRequest{Content: "test"})
|
||||
_, err := svc.SubmitCheckout(t.Context(), 1, 100, SubmitCheckoutRequest{Content: "test"})
|
||||
if !errors.Is(err, ErrDependencyUnavailable) {
|
||||
t.Fatalf("SubmitCheckout() error = %v, want ErrDependencyUnavailable", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user