Backport #29254 The tests on migration tests failed but CI reports successfully https://github.com/go-gitea/gitea/actions/runs/7364373807/job/20044685969#step:8:141 This PR will fix the bug on migrations and also the CI hidden behaviour. The reason is on the Makefile `GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(MIGRATE_TEST_PACKAGES)` will return the error exit code. But `for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ done` will not work. --------- Co-authored-by: Giteabot <teabot@gitea.io>tags/v1.21.8
- run: make backend | - run: make backend | ||||
env: | env: | ||||
TAGS: bindata | TAGS: bindata | ||||
- run: make test-pgsql-migration test-pgsql | |||||
- name: run migration tests | |||||
run: make test-pgsql-migration | |||||
- name: run tests | |||||
run: make test-pgsql | |||||
timeout-minutes: 50 | timeout-minutes: 50 | ||||
env: | env: | ||||
TAGS: bindata gogit | TAGS: bindata gogit | ||||
- run: make backend | - run: make backend | ||||
env: | env: | ||||
TAGS: bindata gogit sqlite sqlite_unlock_notify | TAGS: bindata gogit sqlite sqlite_unlock_notify | ||||
- run: make test-sqlite-migration test-sqlite | |||||
- name: run migration tests | |||||
run: make test-sqlite-migration | |||||
- name: run tests | |||||
run: make test-sqlite | |||||
timeout-minutes: 50 | timeout-minutes: 50 | ||||
env: | env: | ||||
TAGS: bindata gogit sqlite sqlite_unlock_notify | TAGS: bindata gogit sqlite sqlite_unlock_notify | ||||
- run: make backend | - run: make backend | ||||
env: | env: | ||||
TAGS: bindata | TAGS: bindata | ||||
- name: run migration tests | |||||
run: make test-mysql-migration | |||||
- name: run tests | - name: run tests | ||||
run: make test-mysql-migration integration-test-coverage | |||||
run: make integration-test-coverage | |||||
env: | env: | ||||
TAGS: bindata | TAGS: bindata | ||||
RACE_ENABLED: true | RACE_ENABLED: true | ||||
- run: make backend | - run: make backend | ||||
env: | env: | ||||
TAGS: bindata | TAGS: bindata | ||||
- run: make test-mssql-migration test-mssql | |||||
- run: make test-mssql-migration | |||||
- name: run tests | |||||
run: make test-mssql | |||||
timeout-minutes: 50 | timeout-minutes: 50 | ||||
env: | env: | ||||
TAGS: bindata | TAGS: bindata |
GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/)) | GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/)) | ||||
GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/)) | GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/)) | ||||
MIGRATE_TEST_PACKAGES ?= $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) | |||||
FOMANTIC_WORK_DIR := web_src/fomantic | FOMANTIC_WORK_DIR := web_src/fomantic | ||||
.PHONY: migrations.individual.mysql.test | .PHONY: migrations.individual.mysql.test | ||||
migrations.individual.mysql.test: $(GO_SOURCES) | migrations.individual.mysql.test: $(GO_SOURCES) | ||||
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ | |||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ | |||||
done | |||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES) | |||||
.PHONY: migrations.individual.mysql8.test | .PHONY: migrations.individual.mysql8.test | ||||
migrations.individual.mysql8.test: $(GO_SOURCES) | migrations.individual.mysql8.test: $(GO_SOURCES) | ||||
.PHONY: migrations.individual.pgsql.test | .PHONY: migrations.individual.pgsql.test | ||||
migrations.individual.pgsql.test: $(GO_SOURCES) | migrations.individual.pgsql.test: $(GO_SOURCES) | ||||
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ | |||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ | |||||
done | |||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES) | |||||
.PHONY: migrations.individual.pgsql.test\#% | .PHONY: migrations.individual.pgsql.test\#% | ||||
migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql | migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql | ||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$* | GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$* | ||||
.PHONY: migrations.individual.mssql.test | .PHONY: migrations.individual.mssql.test | ||||
migrations.individual.mssql.test: $(GO_SOURCES) generate-ini-mssql | migrations.individual.mssql.test: $(GO_SOURCES) generate-ini-mssql | ||||
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ | |||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg -test.failfast; \ | |||||
done | |||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES) | |||||
.PHONY: migrations.individual.mssql.test\#% | .PHONY: migrations.individual.mssql.test\#% | ||||
migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql | migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql | ||||
.PHONY: migrations.individual.sqlite.test | .PHONY: migrations.individual.sqlite.test | ||||
migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite | migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite | ||||
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ | |||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ | |||||
done | |||||
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES) | |||||
.PHONY: migrations.individual.sqlite.test\#% | .PHONY: migrations.individual.sqlite.test\#% | ||||
migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite | migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite |
"updated_unix", | "updated_unix", | ||||
} | } | ||||
x.SetMapper(names.GonicMapper{}) | |||||
for i := range columns { | for i := range columns { | ||||
x.SetMapper(names.GonicMapper{}) | |||||
if err := x.Sync(new(DropTest)); err != nil { | if err := x.Sync(new(DropTest)); err != nil { | ||||
t.Errorf("unable to create DropTest table: %v", err) | t.Errorf("unable to create DropTest table: %v", err) | ||||
return | return | ||||
} | } | ||||
sess := x.NewSession() | sess := x.NewSession() | ||||
if err := sess.Begin(); err != nil { | if err := sess.Begin(); err != nil { | ||||
sess.Close() | sess.Close() | ||||
return | return | ||||
} | } | ||||
for j := range columns[i+1:] { | for j := range columns[i+1:] { | ||||
x.SetMapper(names.GonicMapper{}) | |||||
if err := x.Sync(new(DropTest)); err != nil { | if err := x.Sync(new(DropTest)); err != nil { | ||||
t.Errorf("unable to create DropTest table: %v", err) | t.Errorf("unable to create DropTest table: %v", err) | ||||
return | return |
- | |||||
id: 1 | |||||
repo_id: 1 | |||||
index: 1 |
- | |||||
id: 1 | |||||
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11 | |||||
issue_id: 1 | |||||
release_id: 0 | |||||
- | |||||
id: 2 | |||||
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12 | |||||
issue_id: 0 | |||||
release_id: 1 |
- | |||||
id: 1 | |||||
repo_id: 1 |
- | |||||
id: 1 | |||||
repo_id: 1 |
type Attachment struct { | type Attachment struct { | ||||
ID int64 `xorm:"pk autoincr"` | ID int64 `xorm:"pk autoincr"` | ||||
UUID string `xorm:"uuid UNIQUE"` | UUID string `xorm:"uuid UNIQUE"` | ||||
RepoID int64 `xorm:"INDEX"` // this should not be zero | |||||
IssueID int64 `xorm:"INDEX"` // maybe zero when creating | IssueID int64 `xorm:"INDEX"` // maybe zero when creating | ||||
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating | ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating | ||||
UploaderID int64 `xorm:"INDEX DEFAULT 0"` | UploaderID int64 `xorm:"INDEX DEFAULT 0"` | ||||
return | return | ||||
} | } | ||||
var issueAttachments []*Attachment | |||||
err := x.Where("issue_id > 0").Find(&issueAttachments) | |||||
type NewAttachment struct { | |||||
ID int64 `xorm:"pk autoincr"` | |||||
UUID string `xorm:"uuid UNIQUE"` | |||||
RepoID int64 `xorm:"INDEX"` // this should not be zero | |||||
IssueID int64 `xorm:"INDEX"` // maybe zero when creating | |||||
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating | |||||
UploaderID int64 `xorm:"INDEX DEFAULT 0"` | |||||
} | |||||
var issueAttachments []*NewAttachment | |||||
err := x.Table("attachment").Where("issue_id > 0").Find(&issueAttachments) | |||||
assert.NoError(t, err) | assert.NoError(t, err) | ||||
for _, attach := range issueAttachments { | for _, attach := range issueAttachments { | ||||
assert.Greater(t, attach.RepoID, 0) | |||||
assert.Greater(t, attach.IssueID, 0) | |||||
assert.Greater(t, attach.RepoID, int64(0)) | |||||
assert.Greater(t, attach.IssueID, int64(0)) | |||||
var issue Issue | var issue Issue | ||||
has, err := x.ID(attach.IssueID).Get(&issue) | has, err := x.ID(attach.IssueID).Get(&issue) | ||||
assert.NoError(t, err) | assert.NoError(t, err) | ||||
assert.EqualValues(t, attach.RepoID, issue.RepoID) | assert.EqualValues(t, attach.RepoID, issue.RepoID) | ||||
} | } | ||||
var releaseAttachments []*Attachment | |||||
err = x.Where("release_id > 0").Find(&releaseAttachments) | |||||
var releaseAttachments []*NewAttachment | |||||
err = x.Table("attachment").Where("release_id > 0").Find(&releaseAttachments) | |||||
assert.NoError(t, err) | assert.NoError(t, err) | ||||
for _, attach := range releaseAttachments { | for _, attach := range releaseAttachments { | ||||
assert.Greater(t, attach.RepoID, 0) | |||||
assert.Greater(t, attach.IssueID, 0) | |||||
assert.Greater(t, attach.RepoID, int64(0)) | |||||
assert.Greater(t, attach.ReleaseID, int64(0)) | |||||
var release Release | var release Release | ||||
has, err := x.ID(attach.ReleaseID).Get(&release) | has, err := x.ID(attach.ReleaseID).Get(&release) | ||||
assert.NoError(t, err) | assert.NoError(t, err) |