mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-08-02 12:53:08 +00:00
An unchecked type assertion panics on input it did not expect, as a missing `tool_cache` key did in https://gitea.com/gitea/runner/pulls/1122.
Every flagged site is now handled where it can fail, or typed so it cannot: a `lock.Keyed` replaces the two `sync.Map` mutex registries, and the reporter's outputs carry an explicit sent flag. Mocks keep their assertions, a mismatch there is a setup error the panic names.
Bugs it turned up (only the first is reachable from workflows):
1. A scalar `matrix.include` or `matrix.exclude`, e.g. `include: foo` or `include: [1, 2]`, panicked the runner with `interface conversion: interface {} is string, not map[string]interface {}`. Verified against `main`, it is now a workflow error. `OnSchedule` panicked the same way on a malformed `on.schedule` entry.
1. `ExternalURL()` panicked on the nil listener after `Close()`, the port is now resolved once at startup.
1. `errors.Is(err, git.ErrShortRef)` followed by `err.(*git.Error)` panics as soon as anything wraps that error, so it is `errors.As` now.
1. An output name the server acknowledged without ever being sent one was recorded as sent forever, which silently dropped a later value for that name.
48576ab3e5 fixes one discovered issue: a matrix key holding a nested object was logged and then run as if the job had no matrix, so it now fails like an unknown `exclude` key.
Reviewed-on: https://gitea.com/gitea/runner/pulls/1123
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: silverwind <me@silverwind.io>
63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package container
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCreateFlagsFromOptions(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
options string
|
|
platform string
|
|
pull string
|
|
}{
|
|
{"", "", pullPolicyMissing},
|
|
{"-v /a:/b --platform=linux/arm64 --pull always", "linux/arm64", pullPolicyAlways},
|
|
{"--platform linux/arm/v7 --pull never", "linux/arm/v7", pullPolicyNever},
|
|
{`--platform "linux/amd64`, "", pullPolicyMissing}, // malformed, defaults kept
|
|
} {
|
|
t.Run(tc.options, func(t *testing.T) {
|
|
cf := createFlagsFromOptions(tc.options)
|
|
assert.Equal(t, tc.platform, cf.platform)
|
|
assert.Equal(t, tc.pull, cf.pull)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCreateFlagsValidate(t *testing.T) {
|
|
for _, tc := range []struct {
|
|
options string
|
|
wantErr string
|
|
}{
|
|
{"--quiet --disable-content-trust --name mine", ""},
|
|
{"--pull sometimes", `invalid --pull option "sometimes"`},
|
|
{"--use-api-socket", "--use-api-socket is not supported"},
|
|
} {
|
|
t.Run(tc.options, func(t *testing.T) {
|
|
err := createFlagsFromOptions(tc.options).validate()
|
|
if tc.wantErr == "" {
|
|
require.NoError(t, err)
|
|
return
|
|
}
|
|
require.ErrorContains(t, err, tc.wantErr)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNewContainerAppliesCreateFlags(t *testing.T) {
|
|
input := &NewContainerInput{Platform: "linux/amd64", Options: "--platform linux/arm64 --pull never"}
|
|
cr, ok := NewContainer(input).(*containerReference)
|
|
require.True(t, ok)
|
|
assert.Equal(t, "linux/arm64", input.Platform)
|
|
assert.Equal(t, pullPolicyNever, cr.pullPolicy)
|
|
|
|
kept := &NewContainerInput{Platform: "linux/amd64", Options: "--privileged"}
|
|
NewContainer(kept)
|
|
assert.Equal(t, "linux/amd64", kept.Platform)
|
|
}
|