refactor: add migrator tests

This commit is contained in:
johnnyjoy
2025-06-11 20:49:26 +08:00
parent 3490aad98e
commit 3c00c5adaa
13 changed files with 35 additions and 163 deletions
+34 -6
View File
@@ -1,17 +1,45 @@
package teststore
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/yourselfhosted/slash/server/common"
"github.com/yourselfhosted/slash/server/profile"
"github.com/yourselfhosted/slash/store"
)
func TestGetCurrentSchemaVersion(t *testing.T) {
ctx := context.Background()
ts := NewTestingStore(ctx, t)
tests := []struct {
driver string
expected string
}{
{
driver: "sqlite",
expected: "1.0.1",
},
{
driver: "postgres",
expected: "1.0.1",
},
}
currentSchemaVersion, err := ts.GetCurrentSchemaVersion()
require.NoError(t, err)
require.Equal(t, "1.0.1", currentSchemaVersion)
for _, tt := range tests {
t.Run(tt.driver, func(t *testing.T) {
ts := newTestingStoreWithConfig(tt.driver)
currentSchemaVersion, err := ts.GetCurrentSchemaVersion()
require.NoError(t, err)
require.Equal(t, tt.expected, currentSchemaVersion)
})
}
}
// newTestingStoreWithConfig creates a testing store with specific driver configuration
func newTestingStoreWithConfig(driver string) *store.Store {
profile := &profile.Profile{
Mode: "prod",
Driver: driver,
Version: common.GetCurrentVersion("prod"),
}
return store.New(nil, profile)
}