mirror of
https://github.com/go-shiori/shiori.git
synced 2024-09-20 15:06:14 +08:00
test cleanup
This commit is contained in:
parent
7618d4a79d
commit
4386df7b40
|
@ -35,7 +35,6 @@ func testDatabase(t *testing.T, dbFactory testDatabaseFactory) {
|
|||
"testCreateAccount": testCreateAccount,
|
||||
"testDeleteAccount": testDeleteAccount,
|
||||
"testDeleteNonExistantAccount": testDeleteNonExistantAccount,
|
||||
"testSaveAccount": testSaveAccount,
|
||||
"testUpdateAccount": testUpdateAccount,
|
||||
"testGetAccount": testGetAccount,
|
||||
"testListAccounts": testListAccounts,
|
||||
|
@ -376,20 +375,6 @@ func testDeleteNonExistantAccount(t *testing.T, db DB) {
|
|||
assert.ErrorIs(t, err, ErrNotFound, "Delete account must fail")
|
||||
}
|
||||
|
||||
func testSaveAccount(t *testing.T, db DB) {
|
||||
ctx := context.TODO()
|
||||
|
||||
acc := model.Account{
|
||||
Username: "testuser",
|
||||
Config: model.UserConfig{},
|
||||
}
|
||||
|
||||
account, err := db.CreateAccount(ctx, acc)
|
||||
require.Nil(t, err)
|
||||
require.NotNil(t, account)
|
||||
require.NotEmpty(t, account.ID)
|
||||
}
|
||||
|
||||
func testUpdateAccount(t *testing.T, db DB) {
|
||||
ctx := context.TODO()
|
||||
|
||||
|
|
|
@ -68,21 +68,4 @@ func testSqliteGetBookmarksWithDash(t *testing.T) {
|
|||
assert.NoError(t, err, "Get bookmarks should not fail")
|
||||
assert.Len(t, results, 1, "results should contain one item")
|
||||
assert.Equal(t, savedBookmark.ID, results[0].ID, "bookmark should be the one saved")
|
||||
|
||||
}
|
||||
|
||||
func TestSQLiteDatabaseSaveAccountFail(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
|
||||
// Initialize nonexistant database
|
||||
factory := func(ctx context.Context) (DB, error) {
|
||||
return OpenSQLiteDatabase(ctx, filepath.Join(os.TempDir(), "shiori_test.db"))
|
||||
}
|
||||
db, err := factory(ctx)
|
||||
assert.Nil(t, err)
|
||||
|
||||
// Test falid database
|
||||
acc := model.Account{}
|
||||
_, err = db.CreateAccount(ctx, acc)
|
||||
assert.Contains(t, err.Error(), "no such table: account")
|
||||
}
|
||||
|
|
|
@ -58,10 +58,10 @@ func PerformRequestWithRecorder(recorder *httptest.ResponseRecorder, r http.Hand
|
|||
// Keep in mind that this users is not saved in database so any tests that use this middleware
|
||||
// should not rely on database.
|
||||
func FakeUserLoggedInMiddlewware(ctx *gin.Context) {
|
||||
ctx.Set("account", &model.Account{
|
||||
ctx.Set("account", &model.AccountDTO{
|
||||
ID: 1,
|
||||
Username: "user",
|
||||
Owner: false,
|
||||
Owner: model.Ptr(false),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -69,10 +69,10 @@ func FakeUserLoggedInMiddlewware(ctx *gin.Context) {
|
|||
// Keep in mind that this users is not saved in database so any tests that use this middleware
|
||||
// should not rely on database.
|
||||
func FakeAdminLoggedInMiddlewware(ctx *gin.Context) {
|
||||
ctx.Set("account", &model.Account{
|
||||
ctx.Set("account", &model.AccountDTO{
|
||||
ID: 1,
|
||||
Username: "admin",
|
||||
Owner: true,
|
||||
Username: "user",
|
||||
Owner: model.Ptr(true),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue