mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.3 KiB
116 lines
3.3 KiB
8 years ago
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a MIT-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
3 years ago
|
package admin
|
||
8 years ago
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
|
||
8 years ago
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestNotice_TrStr(t *testing.T) {
|
||
|
notice := &Notice{
|
||
|
Type: NoticeRepository,
|
||
|
Description: "test description",
|
||
|
}
|
||
|
assert.Equal(t, "admin.notices.type_1", notice.TrStr())
|
||
|
}
|
||
|
|
||
|
func TestCreateNotice(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
8 years ago
|
|
||
|
noticeBean := &Notice{
|
||
|
Type: NoticeRepository,
|
||
|
Description: "test description",
|
||
|
}
|
||
3 years ago
|
unittest.AssertNotExistsBean(t, noticeBean)
|
||
8 years ago
|
assert.NoError(t, CreateNotice(noticeBean.Type, noticeBean.Description))
|
||
3 years ago
|
unittest.AssertExistsAndLoadBean(t, noticeBean)
|
||
8 years ago
|
}
|
||
|
|
||
|
func TestCreateRepositoryNotice(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
8 years ago
|
|
||
|
noticeBean := &Notice{
|
||
|
Type: NoticeRepository,
|
||
|
Description: "test description",
|
||
|
}
|
||
3 years ago
|
unittest.AssertNotExistsBean(t, noticeBean)
|
||
8 years ago
|
assert.NoError(t, CreateRepositoryNotice(noticeBean.Description))
|
||
3 years ago
|
unittest.AssertExistsAndLoadBean(t, noticeBean)
|
||
8 years ago
|
}
|
||
|
|
||
|
// TODO TestRemoveAllWithNotice
|
||
|
|
||
|
func TestCountNotices(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
8 years ago
|
assert.Equal(t, int64(3), CountNotices())
|
||
|
}
|
||
|
|
||
|
func TestNotices(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
8 years ago
|
|
||
|
notices, err := Notices(1, 2)
|
||
|
assert.NoError(t, err)
|
||
7 years ago
|
if assert.Len(t, notices, 2) {
|
||
|
assert.Equal(t, int64(3), notices[0].ID)
|
||
|
assert.Equal(t, int64(2), notices[1].ID)
|
||
|
}
|
||
8 years ago
|
|
||
|
notices, err = Notices(2, 2)
|
||
|
assert.NoError(t, err)
|
||
7 years ago
|
if assert.Len(t, notices, 1) {
|
||
|
assert.Equal(t, int64(1), notices[0].ID)
|
||
|
}
|
||
8 years ago
|
}
|
||
|
|
||
|
func TestDeleteNotice(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
8 years ago
|
|
||
3 years ago
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 3})
|
||
8 years ago
|
assert.NoError(t, DeleteNotice(3))
|
||
3 years ago
|
unittest.AssertNotExistsBean(t, &Notice{ID: 3})
|
||
8 years ago
|
}
|
||
|
|
||
|
func TestDeleteNotices(t *testing.T) {
|
||
|
// delete a non-empty range
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
8 years ago
|
|
||
3 years ago
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 1})
|
||
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 2})
|
||
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 3})
|
||
8 years ago
|
assert.NoError(t, DeleteNotices(1, 2))
|
||
3 years ago
|
unittest.AssertNotExistsBean(t, &Notice{ID: 1})
|
||
|
unittest.AssertNotExistsBean(t, &Notice{ID: 2})
|
||
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 3})
|
||
8 years ago
|
}
|
||
|
|
||
|
func TestDeleteNotices2(t *testing.T) {
|
||
|
// delete an empty range
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
8 years ago
|
|
||
3 years ago
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 1})
|
||
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 2})
|
||
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 3})
|
||
8 years ago
|
assert.NoError(t, DeleteNotices(3, 2))
|
||
3 years ago
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 1})
|
||
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 2})
|
||
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 3})
|
||
8 years ago
|
}
|
||
|
|
||
|
func TestDeleteNoticesByIDs(t *testing.T) {
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
8 years ago
|
|
||
3 years ago
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 1})
|
||
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 2})
|
||
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 3})
|
||
8 years ago
|
assert.NoError(t, DeleteNoticesByIDs([]int64{1, 3}))
|
||
3 years ago
|
unittest.AssertNotExistsBean(t, &Notice{ID: 1})
|
||
|
unittest.AssertExistsAndLoadBean(t, &Notice{ID: 2})
|
||
|
unittest.AssertNotExistsBean(t, &Notice{ID: 3})
|
||
8 years ago
|
}
|