testutil

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	T0 = time.Unix(1784505880, 0).UTC() // campaign snapshot time
)

Base timestamps matching real API data (season 159)

Functions

func AttackEventActive

func AttackEventActive() domain.AttackEvent

func AttackEventFailed

func AttackEventFailed() domain.AttackEvent

func AttackEventSucceeded

func AttackEventSucceeded() domain.AttackEvent

func CampaignWithActiveAttack

func CampaignWithActiveAttack() *domain.CampaignStatus

func CampaignWithActiveDefend

func CampaignWithActiveDefend() *domain.CampaignStatus

func CampaignWithEndedAttack

func CampaignWithEndedAttack() *domain.CampaignStatus

func CampaignWithFailedDefend

func CampaignWithFailedDefend() *domain.CampaignStatus

func CampaignWithNoDefend

func CampaignWithNoDefend() *domain.CampaignStatus

func CampaignWithSucceededDefend

func CampaignWithSucceededDefend() *domain.CampaignStatus

func DefendEventActive

func DefendEventActive() *domain.DefendEvent

func DefendEventFailed

func DefendEventFailed() *domain.DefendEvent

func DefendEventNewActive

func DefendEventNewActive() *domain.DefendEvent

func DefendEventSucceeded

func DefendEventSucceeded() *domain.DefendEvent

func DiscardLogger

func DiscardLogger() *slog.Logger

DiscardLogger returns a logger that discards all output. Useful in tests that don't care about log output.

func FactionStatuses

func FactionStatuses() []domain.FactionStatus

Types

type APIAttackEvent

type APIAttackEvent struct {
	Season         int    `json:"season"`
	ID             int    `json:"event_id"`
	StartTime      int    `json:"start_time"`
	EndTime        int    `json:"end_time"`
	Enemy          int    `json:"enemy"`
	PointsMax      int    `json:"points_max"`
	Points         int    `json:"points"`
	Status         string `json:"status"`
	PlayersAtStart int    `json:"players_at_start"`
	MaxEventID     int    `json:"max_event_id"`
}

type APIDefendEvent

type APIDefendEvent struct {
	Season         int    `json:"season"`
	ID             int    `json:"event_id"`
	StartTime      int    `json:"start_time"`
	EndTime        int    `json:"end_time"`
	Region         int    `json:"region"`
	Enemy          int    `json:"enemy"`
	PointsMax      int    `json:"points_max"`
	Points         int    `json:"points"`
	Status         string `json:"status"`
	PlayersAtStart int    `json:"players_at_start"`
}

type APIFactionStatus

type APIFactionStatus struct {
	Season            int    `json:"season"`
	Points            int    `json:"points"`
	PointsTaken       int    `json:"points_taken"`
	PointsMax         int    `json:"points_max"`
	Status            string `json:"status"`
	IntroductionOrder int    `json:"introduction_order"`
}

type APIResponse

type APIResponse struct {
	Time          int                `json:"time"`
	ErrorCode     int                `json:"error_code"`
	FactionStatus []APIFactionStatus `json:"campaign_status"`
	DefendEvent   APIDefendEvent     `json:"defend_event"`
	AttackEvents  []APIAttackEvent   `json:"attack_events"`
	Statistics    []APIStatistics    `json:"statistics"`
}

APIResponse is the wire format returned by the Helldivers 1 API for the "get_campaign_status" action. It mirrors the private apiCampaignStatus type in the helldivers1api package so that tests can construct responses without importing internal types.

func RestartScenario

func RestartScenario() (partA, partB []APIResponse)

RestartScenario returns two separate sequences to simulate a bot restart mid-war. The bot runs on PartA (wars 50–52), is stopped, then restarted on PartB (starting at war 53). The first poll of PartB should be treated as a fresh start (no previous campaign in store) — the bot must not emit stale notifications for events that happened during the downtime.

PartA sequence (war 50, bot stops after this):

poll 1: idle (stored, no diff)
poll 2: attack starts → notify started
poll 3: attack still active (no notification)

PartB sequence (war 53, fresh store):

poll 1: war is already at season 53, attack 600 active → stored as baseline, no diff
poll 2: attack 600 still active → stored in event store, notify started
poll 3: attack 600 succeeded → notify succeeded

func WarScenario

func WarScenario() []APIResponse

WarScenario returns a sequence of APIResponses that simulate a complete Helldivers 1 war from idle to war-won. The sequence is:

  1. Idle — no events (first poll; poller saves but does not diff)
  2. Attack event starts (active)
  3. Attack event still active (no notification expected)
  4. Attack event succeeded
  5. Idle — no events
  6. Defend event starts (active)
  7. Defend event still active (no notification expected)
  8. Defend event succeeded
  9. War ends (season increments, all factions defeated → war won)

Expected notifications (8 total):

  • poll 2: attack started
  • poll 4: attack succeeded
  • poll 6: defend started
  • poll 8: defend succeeded
  • poll 9: war won

type APIStatistics

type APIStatistics struct {
	Season                 int `json:"season"`
	SeasonDuration         int `json:"season_duration"`
	Enemy                  int `json:"enemy"`
	Players                int `json:"players"`
	TotalUniquePlayers     int `json:"total_unique_players"`
	Missions               int `json:"missions"`
	SuccessfulMissions     int `json:"successful_missions"`
	TotalMissionDifficulty int `json:"total_mission_difficulty"`
	CompletedPlanets       int `json:"completed_planets"`
	DefendEvents           int `json:"defend_events"`
	SuccessfulDefendEvents int `json:"successful_defend_events"`
	AttackEvents           int `json:"attack_events"`
	SuccessfulAttackEvents int `json:"successful_attack_events"`
	Deaths                 int `json:"deaths"`
	Kills                  int `json:"kills"`
	Accidentals            int `json:"accidentals"`
	Shots                  int `json:"shots"`
	Hits                   int `json:"hits"`
}

type ErrorStore

type ErrorStore struct{}

ErrorStore implements port.CampaignStore and port.EventStore, returning errors for every operation. Used to test error-handling paths in the poller.

func (*ErrorStore) GetOngoingEvent

func (e *ErrorStore) GetOngoingEvent(_ int, _ domain.EventKind) (*domain.OngoingEvent, error)

func (*ErrorStore) LatestCampaign

func (e *ErrorStore) LatestCampaign() (*domain.CampaignStatus, error)

func (*ErrorStore) ListOngoingEvents

func (e *ErrorStore) ListOngoingEvents(_ domain.EventKind) ([]*domain.OngoingEvent, error)

func (*ErrorStore) RemoveOngoingEvent

func (e *ErrorStore) RemoveOngoingEvent(_ int, _ domain.EventKind) error

func (*ErrorStore) SaveCampaign

func (e *ErrorStore) SaveCampaign(_ *domain.CampaignStatus) error

func (*ErrorStore) SaveOngoingEvent

func (e *ErrorStore) SaveOngoingEvent(_ int, _ domain.EventKind) error

type MockFetcher

type MockFetcher struct {
	Campaign *domain.CampaignStatus
	Err      error
}

func (*MockFetcher) FetchCampaign

func (m *MockFetcher) FetchCampaign() (*domain.CampaignStatus, error)

type MockNotifier

type MockNotifier struct {
	Messages []domain.EventMessage
	// contains filtered or unexported fields
}

func (*MockNotifier) Count

func (m *MockNotifier) Count() int

func (*MockNotifier) First

func (m *MockNotifier) First() *domain.EventMessage

func (*MockNotifier) Last

func (m *MockNotifier) Last() *domain.EventMessage

func (*MockNotifier) Notify

func (m *MockNotifier) Notify(msg domain.EventMessage) error

func (*MockNotifier) Reset

func (m *MockNotifier) Reset()

type MockServer

type MockServer struct {
	Server *httptest.Server
	// contains filtered or unexported fields
}

MockServer is an httptest.Server that serves Helldivers 1 API responses from a pre-loaded sequence, advancing one step per request. When the sequence is exhausted it keeps returning the last response.

func NewMockServer

func NewMockServer(responses []APIResponse) *MockServer

NewMockServer creates and starts a MockServer loaded with the given sequence of responses.

func (*MockServer) CallCount

func (ms *MockServer) CallCount() int

CallCount returns how many requests have been served.

func (*MockServer) Close

func (ms *MockServer) Close()

Close shuts down the mock server.

func (*MockServer) URL

func (ms *MockServer) URL() string

URL returns the base URL of the mock server (suitable for helldivers1api.Options.BaseURL).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL