test cleanup

This commit is contained in:
Felipe M. 2024-06-08 18:22:16 +02:00
parent 7618d4a79d
commit 4386df7b40
No known key found for this signature in database
GPG key ID: CCFBC5637D4000A8
3 changed files with 5 additions and 37 deletions

View file

@ -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()

View file

@ -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")
}

View file

@ -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),
})
}