Files
lijiaoqiao/supply-api/internal/httpapi/alert_api_test.go

56 lines
1.2 KiB
Go
Raw Normal View History

2026-04-14 11:52:45 +08:00
package httpapi
import (
"context"
"testing"
"lijiaoqiao/supply-api/internal/audit/model"
"lijiaoqiao/supply-api/internal/audit/service"
)
type recordingAlertStore struct {
createCalls int
}
func (s *recordingAlertStore) Create(ctx context.Context, alert *model.Alert) error {
s.createCalls++
return nil
}
func (s *recordingAlertStore) GetByID(ctx context.Context, alertID string) (*model.Alert, error) {
return nil, service.ErrAlertNotFound
}
func (s *recordingAlertStore) Update(ctx context.Context, alert *model.Alert) error {
return nil
}
func (s *recordingAlertStore) Delete(ctx context.Context, alertID string) error {
return nil
}
func (s *recordingAlertStore) List(ctx context.Context, filter *model.AlertFilter) ([]*model.Alert, int64, error) {
return nil, 0, nil
}
func TestNewAlertAPI_UsesInjectedStore(t *testing.T) {
store := &recordingAlertStore{}
api, err := NewAlertAPI(service.NewAlertService(store))
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
2026-04-14 11:52:45 +08:00
if api == nil {
t.Fatal("expected api")
}
}
func TestNewAlertAPI_ReturnsErrorWhenServiceMissing(t *testing.T) {
api, err := NewAlertAPI(nil)
if err == nil {
t.Fatal("expected error")
}
if api != nil {
t.Fatal("expected nil api")
}
}