mirror of
https://github.com/aykhans/slash-e.git
synced 2026-09-24 23:06:48 +00:00
refactor: add migrator tests
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user