forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Clear up old Actions logs (go-gitea#31735) Fix createElementFromAttrs bug (go-gitea#31751) bump vue-bar-graph (go-gitea#31705) Use UTC as default timezone when schedule Actions cron tasks (go-gitea#31742) Add permission description for API to add repo collaborator (go-gitea#31744) Clarify Actions resources ownership (go-gitea#31724) Exclude protected branches from recently pushed (go-gitea#31748) [skip ci] Updated translations via Crowdin Distinguish LFS object errors to ignore missing objects during migration (go-gitea#31702)
- Loading branch information
Showing
47 changed files
with
531 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package actions | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestActionScheduleSpec_Parse(t *testing.T) { | ||
// Mock the local timezone is not UTC | ||
local := time.Local | ||
tz, err := time.LoadLocation("Asia/Shanghai") | ||
require.NoError(t, err) | ||
defer func() { | ||
time.Local = local | ||
}() | ||
time.Local = tz | ||
|
||
now, err := time.Parse(time.RFC3339, "2024-07-31T15:47:55+08:00") | ||
require.NoError(t, err) | ||
|
||
tests := []struct { | ||
name string | ||
spec string | ||
want string | ||
wantErr assert.ErrorAssertionFunc | ||
}{ | ||
{ | ||
name: "regular", | ||
spec: "0 10 * * *", | ||
want: "2024-07-31T10:00:00Z", | ||
wantErr: assert.NoError, | ||
}, | ||
{ | ||
name: "invalid", | ||
spec: "0 10 * *", | ||
want: "", | ||
wantErr: assert.Error, | ||
}, | ||
{ | ||
name: "with timezone", | ||
spec: "TZ=America/New_York 0 10 * * *", | ||
want: "2024-07-31T14:00:00Z", | ||
wantErr: assert.NoError, | ||
}, | ||
{ | ||
name: "timezone irrelevant", | ||
spec: "@every 5m", | ||
want: "2024-07-31T07:52:55Z", | ||
wantErr: assert.NoError, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
s := &ActionScheduleSpec{ | ||
Spec: tt.spec, | ||
} | ||
got, err := s.Parse() | ||
tt.wantErr(t, err) | ||
|
||
if err == nil { | ||
assert.Equal(t, tt.want, got.Next(now).UTC().Format(time.RFC3339)) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.