...

Source file src/github.com/ory/x/popx/migration_box_template_test.go

Documentation: github.com/ory/x/popx

     1  package popx
     2  
     3  import (
     4  	"embed"
     5  	"testing"
     6  
     7  	"github.com/gobuffalo/pop/v5"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"github.com/stretchr/testify/require"
    11  
    12  	"github.com/ory/x/logrusx"
    13  )
    14  
    15  //go:embed stub/migrations/templating/*.sql
    16  var templatingMigrations embed.FS
    17  
    18  func TestMigrationBoxTemplating(t *testing.T) {
    19  	templateVals := map[string]interface{}{
    20  		"tableName": "test_table_name",
    21  	}
    22  
    23  	expectedMigration, err := templatingMigrations.ReadFile("stub/migrations/templating/0_sql_create_tablename_template.expected.sql")
    24  	require.NoError(t, err)
    25  
    26  	c, err := pop.NewConnection(&pop.ConnectionDetails{
    27  		URL: "sqlite://file::memory:?_fk=true",
    28  	})
    29  	require.NoError(t, err)
    30  	require.NoError(t, c.Open())
    31  
    32  	_, err = NewMigrationBox(templatingMigrations, NewMigrator(c, logrusx.New("", ""), nil, 0), WithTemplateValues(templateVals), WithMigrationContentMiddleware(func(content string, err error) (string, error) {
    33  		require.NoError(t, err)
    34  		assert.Equal(t, string(expectedMigration), content)
    35  
    36  		return content, err
    37  	}))
    38  	require.NoError(t, err)
    39  }
    40  

View as plain text