testutil

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeSHA256

func ComputeSHA256(data []byte) string

ComputeSHA256 computes the SHA256 hash of data.

Types

type CronScheduler

type CronScheduler interface {
	AddFunc(spec string, cmd func()) (cron.EntryID, error)
	Remove(id cron.EntryID)
	Start()
	Stop()
	Entries() []cron.Entry
}

CronScheduler is an interface for cron scheduling (for mocking).

type MockCronJob

type MockCronJob struct {
	ID      cron.EntryID
	Spec    string
	Func    func()
	Removed bool
}

MockCronJob represents a cron job in the mock.

type MockCronScheduler

type MockCronScheduler struct {

	// Track added jobs
	Jobs map[cron.EntryID]*MockCronJob

	// Control behavior
	AddFuncError error
	Started      bool
	// contains filtered or unexported fields
}

MockCronScheduler is a mock cron scheduler for testing.

func NewMockCronScheduler

func NewMockCronScheduler() *MockCronScheduler

NewMockCronScheduler creates a new mock cron scheduler.

func (*MockCronScheduler) AddFunc

func (m *MockCronScheduler) AddFunc(spec string, cmd func()) (cron.EntryID, error)

AddFunc adds a cron job to the mock.

func (*MockCronScheduler) Entries

func (m *MockCronScheduler) Entries() []cron.Entry

Entries returns all cron entries (mock implementation).

func (*MockCronScheduler) GetJob

func (m *MockCronScheduler) GetJob(id cron.EntryID) *MockCronJob

GetJob returns a cron job by ID (for testing).

func (*MockCronScheduler) GetJobBySpec

func (m *MockCronScheduler) GetJobBySpec(spec string) *MockCronJob

GetJobBySpec returns the first cron job matching the spec (for testing).

func (*MockCronScheduler) Remove

func (m *MockCronScheduler) Remove(id cron.EntryID)

Remove removes a cron job from the mock.

func (*MockCronScheduler) Reset

func (m *MockCronScheduler) Reset()

Reset clears all jobs.

func (*MockCronScheduler) Start

func (m *MockCronScheduler) Start()

Start marks the scheduler as started.

func (*MockCronScheduler) Stop

func (m *MockCronScheduler) Stop()

Stop marks the scheduler as stopped.

func (*MockCronScheduler) TriggerJob

func (m *MockCronScheduler) TriggerJob(id cron.EntryID)

TriggerJob manually triggers a cron job by ID (for testing).

type MockHTTPServer

type MockHTTPServer struct {
	Server *httptest.Server

	// Track download requests
	Downloads []string

	// Control behavior
	FailOnPath map[string]bool
	FileData   map[string][]byte
	// contains filtered or unexported fields
}

MockHTTPServer is a test HTTP server for simulating JAR downloads.

func NewMockHTTPServer

func NewMockHTTPServer() *MockHTTPServer

NewMockHTTPServer creates a new mock HTTP server.

func (*MockHTTPServer) AddFile

func (m *MockHTTPServer) AddFile(path string, data []byte)

AddFile adds a file to be served at the given path.

func (*MockHTTPServer) Close

func (m *MockHTTPServer) Close()

Close shuts down the mock server.

func (*MockHTTPServer) GetDownloads

func (m *MockHTTPServer) GetDownloads() []string

GetDownloads returns a copy of recorded download paths.

func (*MockHTTPServer) Reset

func (m *MockHTTPServer) Reset()

Reset clears all tracking data.

func (*MockHTTPServer) SetFailOnPath

func (m *MockHTTPServer) SetFailOnPath(path string, fail bool)

SetFailOnPath makes the server return an error for the given path.

func (*MockHTTPServer) URL

func (m *MockHTTPServer) URL() string

URL returns the base URL of the mock server.

type RealCronScheduler

type RealCronScheduler struct {
	*cron.Cron
}

RealCronScheduler wraps robfig/cron for production use.

func NewRealCronScheduler

func NewRealCronScheduler() *RealCronScheduler

NewRealCronScheduler creates a production cron scheduler.

func (*RealCronScheduler) Start

func (r *RealCronScheduler) Start()

Start starts the cron scheduler.

func (*RealCronScheduler) Stop

func (r *RealCronScheduler) Stop()

Stop stops the cron scheduler.

Jump to

Keyboard shortcuts

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