Rename the main module to gotea.dev and the binary to gotea, and update the application name and English locale. Keep the external gitea.dev/sdk and gitea.dev/actionslib module imports unchanged. Assisted-by: OpenCode:DeepSeek-V4.1-Flash
90 lines
1.9 KiB
Go
90 lines
1.9 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package actions
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"gotea.dev/modules/timeutil"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestShouldPersistLastOnline(t *testing.T) {
|
|
now := time.Now()
|
|
tests := []struct {
|
|
name string
|
|
last timeutil.TimeStamp
|
|
want bool
|
|
}{
|
|
{
|
|
name: "fresh, skip write",
|
|
last: timeutil.TimeStamp(now.Add(-5 * time.Second).Unix()),
|
|
want: false,
|
|
},
|
|
{
|
|
name: "exactly at interval, write",
|
|
last: timeutil.TimeStamp(now.Add(-RunnerHeartbeatInterval).Unix()),
|
|
want: true,
|
|
},
|
|
{
|
|
name: "stale, write",
|
|
last: timeutil.TimeStamp(now.Add(-2 * RunnerHeartbeatInterval).Unix()),
|
|
want: true,
|
|
},
|
|
{
|
|
name: "zero (never seen), write",
|
|
last: 0,
|
|
want: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Equal(t, tt.want, ShouldPersistLastOnline(tt.last, now))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestShouldPersistLastActive(t *testing.T) {
|
|
now := time.Now()
|
|
tests := []struct {
|
|
name string
|
|
last timeutil.TimeStamp
|
|
want bool
|
|
}{
|
|
{
|
|
name: "fresh, skip write",
|
|
last: timeutil.TimeStamp(now.Add(-1 * time.Second).Unix()),
|
|
want: false,
|
|
},
|
|
{
|
|
name: "exactly at interval, write",
|
|
last: timeutil.TimeStamp(now.Add(-RunnerActiveInterval).Unix()),
|
|
want: true,
|
|
},
|
|
{
|
|
name: "stale, write",
|
|
last: timeutil.TimeStamp(now.Add(-2 * RunnerActiveInterval).Unix()),
|
|
want: true,
|
|
},
|
|
{
|
|
name: "zero (never seen), write",
|
|
last: 0,
|
|
want: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assert.Equal(t, tt.want, ShouldPersistLastActive(tt.last, now))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCanMatchLabelsCaseInsensitive(t *testing.T) {
|
|
runner := &ActionRunner{AgentLabels: []string{"self-hosted", "Linux", "X64"}}
|
|
assert.True(t, runner.CanMatchLabels([]string{"SELF-HOSTED", "linux"}))
|
|
assert.False(t, runner.CanMatchLabels([]string{"linux", "arm64"}))
|
|
}
|