staticbackendhq / core

Backend server API handling user mgmt, database, storage and real-time component
https://staticbackend.com
MIT License
682 stars 66 forks source link

Cleanup database provider tests #124

Open mbezhanov opened 1 week ago

mbezhanov commented 1 week ago

Hi. I'm opening this to initiate a discussion on #80. By introducing a common dbtest package, you could drastically reduce the amount of code required in the *_test.go files.

For example:

package memory

import (
    "testing"

    "github.com/staticbackendhq/core/database/dbtest"
)

func TestFindToken(t *testing.T) {
    dbtest.FindToken(t, datastore, adminToken)
}

func TestFindRootToken(t *testing.T) {
    dbtest.FindRootToken(t, datastore, adminToken)
}

func TestGetRootForBase(t *testing.T) {
    dbtest.GetRootForBase(t, datastore, adminToken)
}

func TestFindTokenByEmail(t *testing.T) {
    dbtest.FindTokenByEmail(t, datastore, adminToken)
}

func TestUserEmailExists(t *testing.T) {
    dbtest.UserEmailExists(t, datastore)
}

func TestAccountList(t *testing.T) {
    dbtest.AccountList(t, datastore)
}

If you like this approach, I'd be happy to apply this for all database provider tests. This will likely reduce the duplicated code with about 30-40%.