An empty api_root now fails at start, for an enabled find_a_tender or fts_mock source and for fetch once

An enabled Find a Tender or mock source with no api_root used to start
and then fail on every fetch. Its worker now returns an error naming the
missing key before it starts, which stops Run. "fetch once" checks
sources.find_a_tender.api_root the same way. TestRunMissingAPIRoot covers
both sources, and TestRunLogsSourceErrors sets an api_root so it still
tests the zero interval. The section docs and internal/config/README.md
say what an empty api_root means.
This commit is contained in:
bwilliams committed 2026-10-15 16:27:49 +01:00
1 parent 67215a6aaa
commit f3a91ad915
7 files changed
+51 -5

No files matched your search

+33
View File
@@ -229,7 +229,9 @@ func TestRunLogsSourceErrors(t *testing.T) {
// A zero interval makes each worker fail straight away.
conf := &config.JobSearchConfig{}
conf.Sources.FindATender.Enabled = true
conf.Sources.FindATender.APIRoot = "http://127.0.0.1:1"
conf.Sources.FTSMock.Enabled = true
conf.Sources.FTSMock.APIRoot = "http://127.0.0.1:1"
conf.Sources.Sleeper.Enabled = true
err := Run(context.Background(), conf, time.Time{})
@@ -248,6 +250,37 @@ func TestRunLogsSourceErrors(t *testing.T) {
}
}
// An enabled Find a Tender or mock source with no api_root fails straight
// away, naming the setting.
func TestRunMissingAPIRoot(t *testing.T) {
quiet := slog.New(slog.DiscardHandler)
tests := []struct {
name string
enable func(*config.JobSearchConfig)
key string
}{
{"find_a_tender", func(conf *config.JobSearchConfig) {
conf.Sources.FindATender.Enabled = true
conf.Sources.FindATender.Interval = time.Hour
}, "sources.find_a_tender.api_root"},
{"fts_mock", func(conf *config.JobSearchConfig) {
conf.Sources.FTSMock.Enabled = true
conf.Sources.FTSMock.Interval = time.Hour
}, "sources.fts_mock.api_root"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
conf := &config.JobSearchConfig{}
tt.enable(conf)
err := Run(context.Background(), conf, time.Time{}, WithLogger(quiet))
if err == nil || !strings.Contains(err.Error(), tt.key) {
t.Errorf("Run = %v; want an error naming %s", err, tt.key)
}
})
}
}
func TestRunNoSourcesEnabled(t *testing.T) {
done := make(chan struct{})
go func() {
+4
View File
@@ -20,6 +20,10 @@ func runFindAOpportunity(
conf *config.JobSearchConfig,
since time.Time,
) error {
if conf.Sources.FindATender.APIRoot == "" {
return errors.New("fetcher: sources.find_a_tender.api_root is not set")
}
worker := util.Worker{
Logger: tagged(logger),
Name: "FindAOpportunity",
+4
View File
@@ -20,6 +20,10 @@ func runFTSMock(
conf *config.JobSearchConfig,
since time.Time,
) error {
if conf.Sources.FTSMock.APIRoot == "" {
return errors.New("fetcher: sources.fts_mock.api_root is not set")
}
worker := util.Worker{
Logger: tagged(logger),
Name: "FTSMock",