Skip to content

Commit 69a2829

Browse files
realaravinthLoïc Dacharywxiaoguang
authored
migrations: a deadline at January 1st, 1970 is valid (#18237)
* migrations: a deadline at January 1st, 1970 is valid Do not change the deadline value if it is set to January 1st, 1970. Setting the deadline to year 9999 when it is zero (which is equal to January 1st, 1970) modifies a deadline set to January 1st, 1970 which is a valid date. In addition, setting a date in year 9999 will be converted to a null date in some cases. Signed-off-by: Loïc Dachary <[email protected]> * tests: set milestone.deadline_unix in fixtures The value of deadline_unix must be set to 253370764800 (i.e. 9999-01-01) in fixtures, otherwise it will be inserted as null which leads to unexpected errors. For instance, DumpRepository will store a null deadline_unix as 0 (i.e. 1970-01-01) and RestoreRepository will change it to 9999-01-01. Signed-off-by: Loïc Dachary <[email protected]> Co-authored-by: Loïc Dachary <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent eaf09a5 commit 69a2829

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

integrations/dump_restore_test.go

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ import (
1515
repo_model "code.gitea.io/gitea/models/repo"
1616
"code.gitea.io/gitea/models/unittest"
1717
user_model "code.gitea.io/gitea/models/user"
18+
base "code.gitea.io/gitea/modules/migration"
1819
"code.gitea.io/gitea/modules/setting"
1920
"code.gitea.io/gitea/modules/structs"
2021
"code.gitea.io/gitea/modules/util"
2122
"code.gitea.io/gitea/services/migrations"
2223

2324
"github.com/stretchr/testify/assert"
25+
"gopkg.in/yaml.v2"
2426
)
2527

2628
func TestDumpRestore(t *testing.T) {
@@ -56,6 +58,8 @@ func TestDumpRestore(t *testing.T) {
5658
var opts = migrations.MigrateOptions{
5759
GitServiceType: structs.GiteaService,
5860
Issues: true,
61+
Labels: true,
62+
Milestones: true,
5963
Comments: true,
6064
AuthToken: token,
6165
CloneAddr: repo.CloneLink().HTTPS,
@@ -68,7 +72,7 @@ func TestDumpRestore(t *testing.T) {
6872
// Verify desired side effects of the dump
6973
//
7074
d := filepath.Join(basePath, repo.OwnerName, repo.Name)
71-
for _, f := range []string{"repo.yml", "topic.yml", "issue.yml"} {
75+
for _, f := range []string{"repo.yml", "topic.yml", "label.yml", "milestone.yml", "issue.yml"} {
7276
assert.FileExists(t, filepath.Join(d, f))
7377
}
7478

@@ -77,7 +81,7 @@ func TestDumpRestore(t *testing.T) {
7781
//
7882

7983
newreponame := "restoredrepo"
80-
err = migrations.RestoreRepository(ctx, d, repo.OwnerName, newreponame, []string{"issues", "comments"})
84+
err = migrations.RestoreRepository(ctx, d, repo.OwnerName, newreponame, []string{"labels", "milestones", "issues", "comments"})
8185
assert.NoError(t, err)
8286

8387
newrepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: newreponame}).(*repo_model.Repository)
@@ -94,11 +98,38 @@ func TestDumpRestore(t *testing.T) {
9498
// Verify the dump of restoredrepo is the same as the dump of repo1
9599
//
96100
newd := filepath.Join(basePath, newrepo.OwnerName, newrepo.Name)
97-
beforeBytes, err := os.ReadFile(filepath.Join(d, "repo.yml"))
101+
for _, filename := range []string{"repo.yml", "label.yml", "milestone.yml"} {
102+
beforeBytes, err := os.ReadFile(filepath.Join(d, filename))
103+
assert.NoError(t, err)
104+
before := strings.ReplaceAll(string(beforeBytes), reponame, newreponame)
105+
after, err := os.ReadFile(filepath.Join(newd, filename))
106+
assert.NoError(t, err)
107+
assert.EqualValues(t, before, string(after))
108+
}
109+
110+
beforeBytes, err := os.ReadFile(filepath.Join(d, "issue.yml"))
98111
assert.NoError(t, err)
99-
before := strings.ReplaceAll(string(beforeBytes), reponame, newreponame)
100-
after, err := os.ReadFile(filepath.Join(newd, "repo.yml"))
112+
var before = make([]*base.Issue, 0, 10)
113+
assert.NoError(t, yaml.Unmarshal(beforeBytes, &before))
114+
afterBytes, err := os.ReadFile(filepath.Join(newd, "issue.yml"))
101115
assert.NoError(t, err)
102-
assert.EqualValues(t, before, string(after))
116+
var after = make([]*base.Issue, 0, 10)
117+
assert.NoError(t, yaml.Unmarshal(afterBytes, &after))
118+
119+
assert.EqualValues(t, len(before), len(after))
120+
if len(before) == len(after) {
121+
for i := 0; i < len(before); i++ {
122+
assert.EqualValues(t, before[i].Number, after[i].Number)
123+
assert.EqualValues(t, before[i].Title, after[i].Title)
124+
assert.EqualValues(t, before[i].Content, after[i].Content)
125+
assert.EqualValues(t, before[i].Ref, after[i].Ref)
126+
assert.EqualValues(t, before[i].Milestone, after[i].Milestone)
127+
assert.EqualValues(t, before[i].State, after[i].State)
128+
assert.EqualValues(t, before[i].IsLocked, after[i].IsLocked)
129+
assert.EqualValues(t, before[i].Created, after[i].Created)
130+
assert.EqualValues(t, before[i].Updated, after[i].Updated)
131+
assert.EqualValues(t, before[i].Labels, after[i].Labels)
132+
}
133+
}
103134
})
104135
}

models/fixtures/milestone.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
is_closed: false
77
num_issues: 1
88
num_closed_issues: 0
9+
deadline_unix: 253370764800
910

1011
-
1112
id: 2
@@ -15,6 +16,7 @@
1516
is_closed: false
1617
num_issues: 0
1718
num_closed_issues: 0
19+
deadline_unix: 253370764800
1820

1921
-
2022
id: 3
@@ -24,6 +26,7 @@
2426
is_closed: true
2527
num_issues: 1
2628
num_closed_issues: 0
29+
deadline_unix: 253370764800
2730

2831
-
2932
id: 4
@@ -33,6 +36,7 @@
3336
is_closed: false
3437
num_issues: 0
3538
num_closed_issues: 0
39+
deadline_unix: 253370764800
3640

3741
-
3842
id: 5
@@ -42,3 +46,4 @@
4246
is_closed: false
4347
num_issues: 0
4448
num_closed_issues: 0
49+
deadline_unix: 253370764800

0 commit comments

Comments
 (0)