forked from supabase/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigration_test.go
More file actions
56 lines (47 loc) · 1.47 KB
/
migration_test.go
File metadata and controls
56 lines (47 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package integration
// Basic imports
import (
"os"
"testing"
gonanoid "github.com/matoous/go-nanoid/v2"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
clicmd "github.com/supabase/cli/cmd"
"github.com/supabase/cli/test/mocks/supabase"
)
type MigrationTestSuite struct {
suite.Suite
tempDir string
cmd *cobra.Command
}
// test functions
func (suite *MigrationTestSuite) TestNewMigration() {
// run command
migration, _, err := suite.cmd.Find([]string{"migration", "new"})
require.NoError(suite.T(), err)
name := gonanoid.MustGenerate(supabase.IDAlphabet, 10)
require.NoError(suite.T(), migration.RunE(migration, []string{name}))
// check migrations file created
subs, err := os.ReadDir("supabase/migrations")
require.NoError(suite.T(), err)
require.Regexp(suite.T(), `[0-9]{14}_`+name+".sql", subs[0].Name())
}
// hooks
func (suite *MigrationTestSuite) SetupTest() {
// init cli
suite.cmd = clicmd.GetRootCmd()
suite.tempDir = NewTempDir(Logger, TempDir)
// init supabase
init, _, err := suite.cmd.Find([]string{"init"})
require.NoError(suite.T(), err)
require.NoError(suite.T(), init.RunE(init, []string{}))
}
func (suite *MigrationTestSuite) TeardownTest() {
require.NoError(suite.T(), os.Chdir(TempDir))
}
// In order for 'go test' to run this suite, we need to create
// a normal test function and pass our suite to suite.Run
func TestMigrationTestSuite(t *testing.T) {
suite.Run(t, new(MigrationTestSuite))
}