mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-01-06 23:25:29 +00:00
Improve Actions test (#32883) (followup)
This commit is contained in:
parent
b18dcd69f2
commit
37f05617a5
3 changed files with 33 additions and 17 deletions
|
@ -15,6 +15,7 @@ import (
|
||||||
auth_model "code.gitea.io/gitea/models/auth"
|
auth_model "code.gitea.io/gitea/models/auth"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
|
||||||
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
|
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
|
||||||
|
@ -22,6 +23,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestJobWithNeeds(t *testing.T) {
|
func TestJobWithNeeds(t *testing.T) {
|
||||||
|
if !setting.Database.Type.IsSQLite3() {
|
||||||
|
t.Skip()
|
||||||
|
}
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
treePath string
|
treePath string
|
||||||
fileContent string
|
fileContent string
|
||||||
|
@ -31,7 +35,7 @@ func TestJobWithNeeds(t *testing.T) {
|
||||||
{
|
{
|
||||||
treePath: ".gitea/workflows/job-with-needs.yml",
|
treePath: ".gitea/workflows/job-with-needs.yml",
|
||||||
fileContent: `name: job-with-needs
|
fileContent: `name: job-with-needs
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '.gitea/workflows/job-with-needs.yml'
|
- '.gitea/workflows/job-with-needs.yml'
|
||||||
|
@ -62,7 +66,7 @@ jobs:
|
||||||
{
|
{
|
||||||
treePath: ".gitea/workflows/job-with-needs-fail.yml",
|
treePath: ".gitea/workflows/job-with-needs-fail.yml",
|
||||||
fileContent: `name: job-with-needs-fail
|
fileContent: `name: job-with-needs-fail
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '.gitea/workflows/job-with-needs-fail.yml'
|
- '.gitea/workflows/job-with-needs-fail.yml'
|
||||||
|
@ -90,7 +94,7 @@ jobs:
|
||||||
{
|
{
|
||||||
treePath: ".gitea/workflows/job-with-needs-fail-if.yml",
|
treePath: ".gitea/workflows/job-with-needs-fail-if.yml",
|
||||||
fileContent: `name: job-with-needs-fail-if
|
fileContent: `name: job-with-needs-fail-if
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '.gitea/workflows/job-with-needs-fail-if.yml'
|
- '.gitea/workflows/job-with-needs-fail-if.yml'
|
||||||
|
@ -166,6 +170,9 @@ jobs:
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJobNeedsMatrix(t *testing.T) {
|
func TestJobNeedsMatrix(t *testing.T) {
|
||||||
|
if !setting.Database.Type.IsSQLite3() {
|
||||||
|
t.Skip()
|
||||||
|
}
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
treePath string
|
treePath string
|
||||||
fileContent string
|
fileContent string
|
||||||
|
@ -175,7 +182,7 @@ func TestJobNeedsMatrix(t *testing.T) {
|
||||||
{
|
{
|
||||||
treePath: ".gitea/workflows/jobs-outputs-with-matrix.yml",
|
treePath: ".gitea/workflows/jobs-outputs-with-matrix.yml",
|
||||||
fileContent: `name: jobs-outputs-with-matrix
|
fileContent: `name: jobs-outputs-with-matrix
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '.gitea/workflows/jobs-outputs-with-matrix.yml'
|
- '.gitea/workflows/jobs-outputs-with-matrix.yml'
|
||||||
|
@ -194,7 +201,7 @@ jobs:
|
||||||
id: gen_output
|
id: gen_output
|
||||||
run: |
|
run: |
|
||||||
version="${{ matrix.version }}"
|
version="${{ matrix.version }}"
|
||||||
echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
|
echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
|
||||||
job2:
|
job2:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [job1]
|
needs: [job1]
|
||||||
|
@ -241,7 +248,7 @@ jobs:
|
||||||
{
|
{
|
||||||
treePath: ".gitea/workflows/jobs-outputs-with-matrix-failure.yml",
|
treePath: ".gitea/workflows/jobs-outputs-with-matrix-failure.yml",
|
||||||
fileContent: `name: jobs-outputs-with-matrix-failure
|
fileContent: `name: jobs-outputs-with-matrix-failure
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '.gitea/workflows/jobs-outputs-with-matrix-failure.yml'
|
- '.gitea/workflows/jobs-outputs-with-matrix-failure.yml'
|
||||||
|
@ -260,7 +267,7 @@ jobs:
|
||||||
id: gen_output
|
id: gen_output
|
||||||
run: |
|
run: |
|
||||||
version="${{ matrix.version }}"
|
version="${{ matrix.version }}"
|
||||||
echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
|
echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
|
||||||
job2:
|
job2:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: ${{ always() }}
|
if: ${{ always() }}
|
||||||
|
|
|
@ -21,10 +21,14 @@ import (
|
||||||
|
|
||||||
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
|
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDownloadTaskLogs(t *testing.T) {
|
func TestDownloadTaskLogs(t *testing.T) {
|
||||||
|
if !setting.Database.Type.IsSQLite3() {
|
||||||
|
t.Skip()
|
||||||
|
}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
treePath string
|
treePath string
|
||||||
|
@ -35,7 +39,7 @@ func TestDownloadTaskLogs(t *testing.T) {
|
||||||
{
|
{
|
||||||
treePath: ".gitea/workflows/download-task-logs-zstd.yml",
|
treePath: ".gitea/workflows/download-task-logs-zstd.yml",
|
||||||
fileContent: `name: download-task-logs-zstd
|
fileContent: `name: download-task-logs-zstd
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '.gitea/workflows/download-task-logs-zstd.yml'
|
- '.gitea/workflows/download-task-logs-zstd.yml'
|
||||||
|
@ -67,7 +71,7 @@ jobs:
|
||||||
{
|
{
|
||||||
treePath: ".gitea/workflows/download-task-logs-no-zstd.yml",
|
treePath: ".gitea/workflows/download-task-logs-no-zstd.yml",
|
||||||
fileContent: `name: download-task-logs-no-zstd
|
fileContent: `name: download-task-logs-no-zstd
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
paths:
|
paths:
|
||||||
- '.gitea/workflows/download-task-logs-no-zstd.yml'
|
- '.gitea/workflows/download-task-logs-no-zstd.yml'
|
||||||
|
@ -132,7 +136,7 @@ jobs:
|
||||||
logFileName += ".zst"
|
logFileName += ".zst"
|
||||||
}
|
}
|
||||||
_, err := storage.Actions.Stat(logFileName)
|
_, err := storage.Actions.Stat(logFileName)
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// download task logs and check content
|
// download task logs and check content
|
||||||
runIndex := task.Context.GetFields()["run_number"].GetStringValue()
|
runIndex := task.Context.GetFields()["run_number"].GetStringValue()
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
"code.gitea.io/actions-proto-go/runner/v1/runnerv1connect"
|
"code.gitea.io/actions-proto-go/runner/v1/runnerv1connect"
|
||||||
"connectrpc.com/connect"
|
"connectrpc.com/connect"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -63,8 +64,8 @@ func (r *mockRunner) doPing(t *testing.T) {
|
||||||
resp, err := r.client.pingServiceClient.Ping(context.Background(), connect.NewRequest(&pingv1.PingRequest{
|
resp, err := r.client.pingServiceClient.Ping(context.Background(), connect.NewRequest(&pingv1.PingRequest{
|
||||||
Data: "mock-runner",
|
Data: "mock-runner",
|
||||||
}))
|
}))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, "Hello, mock-runner!", resp.Msg.Data)
|
require.Equal(t, "Hello, mock-runner!", resp.Msg.Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockRunner) doRegister(t *testing.T, name, token string, labels []string) {
|
func (r *mockRunner) doRegister(t *testing.T, name, token string, labels []string) {
|
||||||
|
@ -75,11 +76,15 @@ func (r *mockRunner) doRegister(t *testing.T, name, token string, labels []strin
|
||||||
Version: "mock-runner-version",
|
Version: "mock-runner-version",
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
}))
|
}))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
r.client = newMockRunnerClient(resp.Msg.Runner.Uuid, resp.Msg.Runner.Token)
|
r.client = newMockRunnerClient(resp.Msg.Runner.Uuid, resp.Msg.Runner.Token)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockRunner) registerAsRepoRunner(t *testing.T, ownerName, repoName, runnerName string, labels []string) {
|
func (r *mockRunner) registerAsRepoRunner(t *testing.T, ownerName, repoName, runnerName string, labels []string) {
|
||||||
|
if !setting.Database.Type.IsSQLite3() {
|
||||||
|
// registering a mock runner when using a database other than SQLite leaves leftovers
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
session := loginUser(t, ownerName)
|
session := loginUser(t, ownerName)
|
||||||
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
|
||||||
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/actions/runners/registration-token", ownerName, repoName)).AddTokenAuth(token)
|
req := NewRequest(t, "GET", fmt.Sprintf("/api/v1/repos/%s/%s/actions/runners/registration-token", ownerName, repoName)).AddTokenAuth(token)
|
||||||
|
@ -102,7 +107,7 @@ func (r *mockRunner) fetchTask(t *testing.T, timeout ...time.Duration) *runnerv1
|
||||||
resp, err := r.client.runnerServiceClient.FetchTask(context.Background(), connect.NewRequest(&runnerv1.FetchTaskRequest{
|
resp, err := r.client.runnerServiceClient.FetchTask(context.Background(), connect.NewRequest(&runnerv1.FetchTaskRequest{
|
||||||
TasksVersion: 0,
|
TasksVersion: 0,
|
||||||
}))
|
}))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if resp.Msg.Task != nil {
|
if resp.Msg.Task != nil {
|
||||||
task = resp.Msg.Task
|
task = resp.Msg.Task
|
||||||
break
|
break
|
||||||
|
@ -128,7 +133,7 @@ func (r *mockRunner) execTask(t *testing.T, task *runnerv1.Task, outcome *mockTa
|
||||||
Rows: []*runnerv1.LogRow{lr},
|
Rows: []*runnerv1.LogRow{lr},
|
||||||
NoMore: idx == len(outcome.logRows)-1,
|
NoMore: idx == len(outcome.logRows)-1,
|
||||||
}))
|
}))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.EqualValues(t, idx+1, resp.Msg.AckIndex)
|
assert.EqualValues(t, idx+1, resp.Msg.AckIndex)
|
||||||
}
|
}
|
||||||
sentOutputKeys := make([]string, 0, len(outcome.outputs))
|
sentOutputKeys := make([]string, 0, len(outcome.outputs))
|
||||||
|
@ -140,7 +145,7 @@ func (r *mockRunner) execTask(t *testing.T, task *runnerv1.Task, outcome *mockTa
|
||||||
},
|
},
|
||||||
Outputs: map[string]string{outputKey: outputValue},
|
Outputs: map[string]string{outputKey: outputValue},
|
||||||
}))
|
}))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
sentOutputKeys = append(sentOutputKeys, outputKey)
|
sentOutputKeys = append(sentOutputKeys, outputKey)
|
||||||
assert.ElementsMatch(t, sentOutputKeys, resp.Msg.SentOutputs)
|
assert.ElementsMatch(t, sentOutputKeys, resp.Msg.SentOutputs)
|
||||||
}
|
}
|
||||||
|
@ -152,6 +157,6 @@ func (r *mockRunner) execTask(t *testing.T, task *runnerv1.Task, outcome *mockTa
|
||||||
StoppedAt: timestamppb.Now(),
|
StoppedAt: timestamppb.Now(),
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
assert.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, outcome.result, resp.Msg.State.Result)
|
assert.Equal(t, outcome.result, resp.Msg.State.Result)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue