mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-31 21:28:11 +09:00 
			
		
		
		
	Decouple unit test, remove intermediate unittestbridge package (#17662)
				
					
				
			Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
		| @@ -7,7 +7,6 @@ package models | ||||
| import ( | ||||
| 	"testing" | ||||
|  | ||||
| 	"code.gitea.io/gitea/models/db" | ||||
| 	"code.gitea.io/gitea/models/unittest" | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
| @@ -27,9 +26,9 @@ func TestCreateNotice(t *testing.T) { | ||||
| 		Type:        NoticeRepository, | ||||
| 		Description: "test description", | ||||
| 	} | ||||
| 	db.AssertNotExistsBean(t, noticeBean) | ||||
| 	unittest.AssertNotExistsBean(t, noticeBean) | ||||
| 	assert.NoError(t, CreateNotice(noticeBean.Type, noticeBean.Description)) | ||||
| 	db.AssertExistsAndLoadBean(t, noticeBean) | ||||
| 	unittest.AssertExistsAndLoadBean(t, noticeBean) | ||||
| } | ||||
|  | ||||
| func TestCreateRepositoryNotice(t *testing.T) { | ||||
| @@ -39,9 +38,9 @@ func TestCreateRepositoryNotice(t *testing.T) { | ||||
| 		Type:        NoticeRepository, | ||||
| 		Description: "test description", | ||||
| 	} | ||||
| 	db.AssertNotExistsBean(t, noticeBean) | ||||
| 	unittest.AssertNotExistsBean(t, noticeBean) | ||||
| 	assert.NoError(t, CreateRepositoryNotice(noticeBean.Description)) | ||||
| 	db.AssertExistsAndLoadBean(t, noticeBean) | ||||
| 	unittest.AssertExistsAndLoadBean(t, noticeBean) | ||||
| } | ||||
|  | ||||
| // TODO TestRemoveAllWithNotice | ||||
| @@ -71,45 +70,45 @@ func TestNotices(t *testing.T) { | ||||
| func TestDeleteNotice(t *testing.T) { | ||||
| 	assert.NoError(t, unittest.PrepareTestDatabase()) | ||||
|  | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 3}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 3}) | ||||
| 	assert.NoError(t, DeleteNotice(3)) | ||||
| 	db.AssertNotExistsBean(t, &Notice{ID: 3}) | ||||
| 	unittest.AssertNotExistsBean(t, &Notice{ID: 3}) | ||||
| } | ||||
|  | ||||
| func TestDeleteNotices(t *testing.T) { | ||||
| 	// delete a non-empty range | ||||
| 	assert.NoError(t, unittest.PrepareTestDatabase()) | ||||
|  | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 1}) | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 2}) | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 3}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 1}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 2}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 3}) | ||||
| 	assert.NoError(t, DeleteNotices(1, 2)) | ||||
| 	db.AssertNotExistsBean(t, &Notice{ID: 1}) | ||||
| 	db.AssertNotExistsBean(t, &Notice{ID: 2}) | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 3}) | ||||
| 	unittest.AssertNotExistsBean(t, &Notice{ID: 1}) | ||||
| 	unittest.AssertNotExistsBean(t, &Notice{ID: 2}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 3}) | ||||
| } | ||||
|  | ||||
| func TestDeleteNotices2(t *testing.T) { | ||||
| 	// delete an empty range | ||||
| 	assert.NoError(t, unittest.PrepareTestDatabase()) | ||||
|  | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 1}) | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 2}) | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 3}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 1}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 2}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 3}) | ||||
| 	assert.NoError(t, DeleteNotices(3, 2)) | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 1}) | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 2}) | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 3}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 1}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 2}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 3}) | ||||
| } | ||||
|  | ||||
| func TestDeleteNoticesByIDs(t *testing.T) { | ||||
| 	assert.NoError(t, unittest.PrepareTestDatabase()) | ||||
|  | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 1}) | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 2}) | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 3}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 1}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 2}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 3}) | ||||
| 	assert.NoError(t, DeleteNoticesByIDs([]int64{1, 3})) | ||||
| 	db.AssertNotExistsBean(t, &Notice{ID: 1}) | ||||
| 	db.AssertExistsAndLoadBean(t, &Notice{ID: 2}) | ||||
| 	db.AssertNotExistsBean(t, &Notice{ID: 3}) | ||||
| 	unittest.AssertNotExistsBean(t, &Notice{ID: 1}) | ||||
| 	unittest.AssertExistsAndLoadBean(t, &Notice{ID: 2}) | ||||
| 	unittest.AssertNotExistsBean(t, &Notice{ID: 3}) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user