mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-04-25 04:57:31 +00:00

Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (redis) (push) Blocked by required conditions
testing / test-remote-cacher (valkey) (push) Blocked by required conditions
testing / test-remote-cacher (garnet) (push) Blocked by required conditions
testing / test-remote-cacher (redict) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions
This PR depends on https://codeberg.org/forgejo/forgejo/pulls/7510 This PR renames UpdateRunJob to UpdateRunJobWithoutNotification and UpdateRun to UpdateRunWithoutNotification and implements wrapper functions that also call the new ActionRunNowDone notification when needed. This PR can be reviewed commit-by-commit. # Things to Test - [x] GetRunBefore - [ ] integration test for sendActionRunNowDoneNotificationIfNeeded, UpdateRun and UpdateRunJob ## Checklist The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org). ### Tests - I added test coverage for Go changes... - [x] in their respective `*_test.go` for unit tests. - [x] in the `tests/integration` directory if it involves interactions with a live Forgejo server. - I added test coverage for JavaScript changes... - [ ] in `web_src/js/*.test.js` if it can be unit tested. - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)). ### Documentation - [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change. - [x] I did not document these changes and I do not expect someone else to do it. ### Release notes - [ ] I do not want this change to show in the release notes. - [ ] I want the title to show in the release notes with a link to this pull request. - [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title. Co-authored-by: nobody <nobody@example.com> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7491 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: christopher-besch <mail@chris-besch.com> Co-committed-by: christopher-besch <mail@chris-besch.com>
96 lines
2.6 KiB
Go
96 lines
2.6 KiB
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package actions
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"forgejo.org/models/db"
|
|
"forgejo.org/models/unittest"
|
|
"forgejo.org/modules/timeutil"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetRunBefore(t *testing.T) {
|
|
require.NoError(t, unittest.PrepareTestDatabase())
|
|
|
|
// this repo is part of the test database requiring loading "repository.yml" in main_test.go
|
|
var repoID int64 = 1
|
|
|
|
workflowID := "test_workflow"
|
|
|
|
// third completed run
|
|
time1, err := time.Parse(time.RFC3339, "2024-07-31T15:47:55+08:00")
|
|
require.NoError(t, err)
|
|
timeutil.MockSet(time1)
|
|
run1 := ActionRun{
|
|
ID: 1,
|
|
Index: 1,
|
|
RepoID: repoID,
|
|
Stopped: timeutil.TimeStampNow(),
|
|
WorkflowID: workflowID,
|
|
}
|
|
|
|
// fourth completed run
|
|
time2, err := time.Parse(time.RFC3339, "2024-08-31T15:47:55+08:00")
|
|
require.NoError(t, err)
|
|
timeutil.MockSet(time2)
|
|
run2 := ActionRun{
|
|
ID: 2,
|
|
Index: 2,
|
|
RepoID: repoID,
|
|
Stopped: timeutil.TimeStampNow(),
|
|
WorkflowID: workflowID,
|
|
}
|
|
|
|
// second completed run
|
|
time3, err := time.Parse(time.RFC3339, "2024-07-31T15:47:54+08:00")
|
|
require.NoError(t, err)
|
|
timeutil.MockSet(time3)
|
|
run3 := ActionRun{
|
|
ID: 3,
|
|
Index: 3,
|
|
RepoID: repoID,
|
|
Stopped: timeutil.TimeStampNow(),
|
|
WorkflowID: workflowID,
|
|
}
|
|
|
|
// first completed run
|
|
time4, err := time.Parse(time.RFC3339, "2024-06-30T15:47:54+08:00")
|
|
require.NoError(t, err)
|
|
timeutil.MockSet(time4)
|
|
run4 := ActionRun{
|
|
ID: 4,
|
|
Index: 4,
|
|
RepoID: repoID,
|
|
Stopped: timeutil.TimeStampNow(),
|
|
WorkflowID: workflowID,
|
|
}
|
|
require.NoError(t, db.Insert(db.DefaultContext, &run1))
|
|
runBefore, err := GetRunBefore(db.DefaultContext, repoID, run1.Stopped)
|
|
// there is no run before run1
|
|
require.Error(t, err)
|
|
require.Nil(t, runBefore)
|
|
|
|
// now there is only run3 before run1
|
|
require.NoError(t, db.Insert(db.DefaultContext, &run3))
|
|
runBefore, err = GetRunBefore(db.DefaultContext, repoID, run1.Stopped)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, run3.ID, runBefore.ID)
|
|
|
|
// there still is only run3 before run1
|
|
require.NoError(t, db.Insert(db.DefaultContext, &run2))
|
|
runBefore, err = GetRunBefore(db.DefaultContext, repoID, run1.Stopped)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, run3.ID, runBefore.ID)
|
|
|
|
// run4 is further away from run1
|
|
require.NoError(t, db.Insert(db.DefaultContext, &run4))
|
|
runBefore, err = GetRunBefore(db.DefaultContext, repoID, run1.Stopped)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, run3.ID, runBefore.ID)
|
|
}
|