1//go:build cgo && !no_sqlite32// +build cgo,!no_sqlite334package blob56import (7 "math/rand"8 "testing"910 backendtests "github.com/foxcpp/go-imap-backend-tests"11 imapsql "github.com/foxcpp/go-imap-sql"12 "github.com/foxcpp/maddy/framework/module"13 imapsql2 "github.com/foxcpp/maddy/internal/storage/imapsql"14 "github.com/foxcpp/maddy/internal/testutils"15)1617type testBack struct {18 backendtests.Backend19 ExtStore module.BlobStore20}2122func TestStore(t *testing.T, newStore func() module.BlobStore, cleanStore func(module.BlobStore)) {23 // We use go-imap-sql backend and run a subset of24 // go-imap-backend-tests related to loading and saving messages.25 //26 // In the future we should probably switch to using a memory27 // backend for this.2829 backendtests.Whitelist = []string{30 t.Name() + "/Mailbox_CreateMessage",31 t.Name() + "/Mailbox_ListMessages_Body",32 t.Name() + "/Mailbox_CopyMessages",33 t.Name() + "/Mailbox_Expunge",34 t.Name() + "/Mailbox_MoveMessages",35 }3637 initBackend := func() backendtests.Backend {38 randSrc := rand.NewSource(0)39 prng := rand.New(randSrc)40 store := newStore()4142 b, err := imapsql.New("sqlite3", ":memory:",43 imapsql2.ExtBlobStore{Base: store}, imapsql.Opts{44 PRNG: prng,45 Log: testutils.Logger(t, "imapsql"),46 },47 )48 if err != nil {49 panic(err)50 }51 return testBack{Backend: b, ExtStore: store}52 }53 cleanBackend := func(bi backendtests.Backend) {54 b := bi.(testBack)55 if err := b.Backend.(*imapsql.Backend).Close(); err != nil {56 panic(err)57 }58 cleanStore(b.ExtStore)59 }6061 backendtests.RunTests(t, initBackend, cleanBackend)62}