forgejo-runner

git clone git://git.lin.moe/forgejo-runner.git

 1// Copyright 2024 The Forgejo Authors. All rights reserved.
 2// SPDX-License-Identifier: MIT
 3
 4package config
 5
 6import (
 7	"testing"
 8	"time"
 9
10	"github.com/stretchr/testify/assert"
11)
12
13func TestConfigTune(t *testing.T) {
14	c := &Config{
15		Runner: Runner{},
16	}
17
18	t.Run("Public instance tuning", func(t *testing.T) {
19		c.Runner.FetchInterval = 60 * time.Second
20		c.Tune("https://codeberg.org")
21		assert.EqualValues(t, 60*time.Second, c.Runner.FetchInterval)
22
23		c.Runner.FetchInterval = 2 * time.Second
24		c.Tune("https://codeberg.org")
25		assert.EqualValues(t, 30*time.Second, c.Runner.FetchInterval)
26	})
27
28	t.Run("Non-public instance tuning", func(t *testing.T) {
29		c.Runner.FetchInterval = 60 * time.Second
30		c.Tune("https://example.com")
31		assert.EqualValues(t, 60*time.Second, c.Runner.FetchInterval)
32
33		c.Runner.FetchInterval = 2 * time.Second
34		c.Tune("https://codeberg.com")
35		assert.EqualValues(t, 2*time.Second, c.Runner.FetchInterval)
36	})
37}