...
1 package pkgerx
2
3 import (
4 "io/ioutil"
5 "path/filepath"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9
10 "github.com/ory/x/sqlcon/dockertest"
11
12 "github.com/markbates/pkger"
13 "github.com/stretchr/testify/require"
14
15 "github.com/ory/x/logrusx"
16 )
17
18 var testData = pkger.Dir("github.com/ory/x:/pkgerx/testdata")
19
20 func TestMigrationBoxTemplating(t *testing.T) {
21 templateVals := map[string]interface{}{
22 "tableName": "test_table_name",
23 }
24
25 expectedMigration, err := ioutil.ReadFile(filepath.Join("testdata", "0_sql_create_tablename_template.expected.sql"))
26 require.NoError(t, err)
27
28 c := dockertest.ConnectToTestCockroachDBPop(t)
29
30 mb, err := NewMigrationBox(testData, c, logrusx.New("", ""), WithTemplateValues(templateVals), WithMigrationContentMiddleware(func(content string, err error) (string, error) {
31 require.NoError(t, err)
32 assert.Equal(t, string(expectedMigration), content)
33
34 return content, err
35 }))
36 require.NoError(t, err)
37
38 err = mb.Up()
39 require.NoError(t, err)
40 }
41
View as plain text