Skip to content

Commit a8cc73f

Browse files
earl-warrenforgejo-backport-action
authored andcommitted
Improve Actions test (go-gitea#32883) (followup)
(cherry picked from commit 37f0561)
1 parent 7a84081 commit a8cc73f

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

tests/integration/actions_job_test.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ import (
1515
auth_model "code.gitea.io/gitea/models/auth"
1616
"code.gitea.io/gitea/models/unittest"
1717
user_model "code.gitea.io/gitea/models/user"
18+
"code.gitea.io/gitea/modules/setting"
1819
api "code.gitea.io/gitea/modules/structs"
1920

2021
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
2122
"github.com/stretchr/testify/assert"
2223
)
2324

2425
func TestJobWithNeeds(t *testing.T) {
26+
if !setting.Database.Type.IsSQLite3() {
27+
t.Skip()
28+
}
2529
testCases := []struct {
2630
treePath string
2731
fileContent string
@@ -31,7 +35,7 @@ func TestJobWithNeeds(t *testing.T) {
3135
{
3236
treePath: ".gitea/workflows/job-with-needs.yml",
3337
fileContent: `name: job-with-needs
34-
on:
38+
on:
3539
push:
3640
paths:
3741
- '.gitea/workflows/job-with-needs.yml'
@@ -62,7 +66,7 @@ jobs:
6266
{
6367
treePath: ".gitea/workflows/job-with-needs-fail.yml",
6468
fileContent: `name: job-with-needs-fail
65-
on:
69+
on:
6670
push:
6771
paths:
6872
- '.gitea/workflows/job-with-needs-fail.yml'
@@ -90,7 +94,7 @@ jobs:
9094
{
9195
treePath: ".gitea/workflows/job-with-needs-fail-if.yml",
9296
fileContent: `name: job-with-needs-fail-if
93-
on:
97+
on:
9498
push:
9599
paths:
96100
- '.gitea/workflows/job-with-needs-fail-if.yml'
@@ -166,6 +170,9 @@ jobs:
166170
}
167171

168172
func TestJobNeedsMatrix(t *testing.T) {
173+
if !setting.Database.Type.IsSQLite3() {
174+
t.Skip()
175+
}
169176
testCases := []struct {
170177
treePath string
171178
fileContent string
@@ -175,7 +182,7 @@ func TestJobNeedsMatrix(t *testing.T) {
175182
{
176183
treePath: ".gitea/workflows/jobs-outputs-with-matrix.yml",
177184
fileContent: `name: jobs-outputs-with-matrix
178-
on:
185+
on:
179186
push:
180187
paths:
181188
- '.gitea/workflows/jobs-outputs-with-matrix.yml'
@@ -194,7 +201,7 @@ jobs:
194201
id: gen_output
195202
run: |
196203
version="${{ matrix.version }}"
197-
echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
204+
echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
198205
job2:
199206
runs-on: ubuntu-latest
200207
needs: [job1]
@@ -241,7 +248,7 @@ jobs:
241248
{
242249
treePath: ".gitea/workflows/jobs-outputs-with-matrix-failure.yml",
243250
fileContent: `name: jobs-outputs-with-matrix-failure
244-
on:
251+
on:
245252
push:
246253
paths:
247254
- '.gitea/workflows/jobs-outputs-with-matrix-failure.yml'
@@ -260,7 +267,7 @@ jobs:
260267
id: gen_output
261268
run: |
262269
version="${{ matrix.version }}"
263-
echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
270+
echo "output_${version}=${version}" >> "$GITHUB_OUTPUT"
264271
job2:
265272
runs-on: ubuntu-latest
266273
if: ${{ always() }}

tests/integration/actions_log_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ import (
2121

2222
runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
2323
"github.com/stretchr/testify/assert"
24+
"github.com/stretchr/testify/require"
2425
"google.golang.org/protobuf/types/known/timestamppb"
2526
)
2627

2728
func TestDownloadTaskLogs(t *testing.T) {
29+
if !setting.Database.Type.IsSQLite3() {
30+
t.Skip()
31+
}
2832
now := time.Now()
2933
testCases := []struct {
3034
treePath string
@@ -35,7 +39,7 @@ func TestDownloadTaskLogs(t *testing.T) {
3539
{
3640
treePath: ".gitea/workflows/download-task-logs-zstd.yml",
3741
fileContent: `name: download-task-logs-zstd
38-
on:
42+
on:
3943
push:
4044
paths:
4145
- '.gitea/workflows/download-task-logs-zstd.yml'
@@ -67,7 +71,7 @@ jobs:
6771
{
6872
treePath: ".gitea/workflows/download-task-logs-no-zstd.yml",
6973
fileContent: `name: download-task-logs-no-zstd
70-
on:
74+
on:
7175
push:
7276
paths:
7377
- '.gitea/workflows/download-task-logs-no-zstd.yml'
@@ -132,7 +136,7 @@ jobs:
132136
logFileName += ".zst"
133137
}
134138
_, err := storage.Actions.Stat(logFileName)
135-
assert.NoError(t, err)
139+
require.NoError(t, err)
136140

137141
// download task logs and check content
138142
runIndex := task.Context.GetFields()["run_number"].GetStringValue()

tests/integration/actions_runner_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"code.gitea.io/actions-proto-go/runner/v1/runnerv1connect"
2020
"connectrpc.com/connect"
2121
"github.com/stretchr/testify/assert"
22+
"github.com/stretchr/testify/require"
2223
"google.golang.org/protobuf/types/known/timestamppb"
2324
)
2425

@@ -63,8 +64,8 @@ func (r *mockRunner) doPing(t *testing.T) {
6364
resp, err := r.client.pingServiceClient.Ping(context.Background(), connect.NewRequest(&pingv1.PingRequest{
6465
Data: "mock-runner",
6566
}))
66-
assert.NoError(t, err)
67-
assert.Equal(t, "Hello, mock-runner!", resp.Msg.Data)
67+
require.NoError(t, err)
68+
require.Equal(t, "Hello, mock-runner!", resp.Msg.Data)
6869
}
6970

7071
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
7576
Version: "mock-runner-version",
7677
Labels: labels,
7778
}))
78-
assert.NoError(t, err)
79+
require.NoError(t, err)
7980
r.client = newMockRunnerClient(resp.Msg.Runner.Uuid, resp.Msg.Runner.Token)
8081
}
8182

8283
func (r *mockRunner) registerAsRepoRunner(t *testing.T, ownerName, repoName, runnerName string, labels []string) {
84+
if !setting.Database.Type.IsSQLite3() {
85+
// registering a mock runner when using a database other than SQLite leaves leftovers
86+
t.FailNow()
87+
}
8388
session := loginUser(t, ownerName)
8489
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
8590
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
102107
resp, err := r.client.runnerServiceClient.FetchTask(context.Background(), connect.NewRequest(&runnerv1.FetchTaskRequest{
103108
TasksVersion: 0,
104109
}))
105-
assert.NoError(t, err)
110+
require.NoError(t, err)
106111
if resp.Msg.Task != nil {
107112
task = resp.Msg.Task
108113
break
@@ -128,7 +133,7 @@ func (r *mockRunner) execTask(t *testing.T, task *runnerv1.Task, outcome *mockTa
128133
Rows: []*runnerv1.LogRow{lr},
129134
NoMore: idx == len(outcome.logRows)-1,
130135
}))
131-
assert.NoError(t, err)
136+
require.NoError(t, err)
132137
assert.EqualValues(t, idx+1, resp.Msg.AckIndex)
133138
}
134139
sentOutputKeys := make([]string, 0, len(outcome.outputs))
@@ -140,7 +145,7 @@ func (r *mockRunner) execTask(t *testing.T, task *runnerv1.Task, outcome *mockTa
140145
},
141146
Outputs: map[string]string{outputKey: outputValue},
142147
}))
143-
assert.NoError(t, err)
148+
require.NoError(t, err)
144149
sentOutputKeys = append(sentOutputKeys, outputKey)
145150
assert.ElementsMatch(t, sentOutputKeys, resp.Msg.SentOutputs)
146151
}
@@ -152,6 +157,6 @@ func (r *mockRunner) execTask(t *testing.T, task *runnerv1.Task, outcome *mockTa
152157
StoppedAt: timestamppb.Now(),
153158
},
154159
}))
155-
assert.NoError(t, err)
160+
require.NoError(t, err)
156161
assert.Equal(t, outcome.result, resp.Msg.State.Result)
157162
}

0 commit comments

Comments
 (0)