core icon indicating copy to clipboard operation
core copied to clipboard

Cleanup database provider tests

Open mbezhanov opened this issue 1 year ago • 0 comments

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%.

mbezhanov avatar Jun 20 '24 16:06 mbezhanov