github.com/supabase/cli@v1.168.1/test/init_test.go (about) 1 package integration 2 3 // Basic imports 4 import ( 5 "os" 6 "testing" 7 8 "github.com/spf13/cobra" 9 "github.com/stretchr/testify/require" 10 "github.com/stretchr/testify/suite" 11 clicmd "github.com/supabase/cli/cmd" 12 "github.com/supabase/cli/internal/utils" 13 ) 14 15 type InitTestSuite struct { 16 suite.Suite 17 tempDir string 18 cmd *cobra.Command 19 } 20 21 // test functions 22 func (suite *InitTestSuite) TestInit() { 23 // init supabase 24 init, _, err := suite.cmd.Find([]string{"init"}) 25 require.NoError(suite.T(), err) 26 require.NoError(suite.T(), init.RunE(init, []string{})) 27 28 // check if init dir exists 29 _, err = os.Stat(utils.ConfigPath) 30 require.NoError(suite.T(), err) 31 } 32 33 // hooks 34 func (suite *InitTestSuite) SetupTest() { 35 // init cli 36 suite.cmd = clicmd.GetRootCmd() 37 suite.tempDir = NewTempDir(Logger, TempDir) 38 } 39 40 func (suite *InitTestSuite) TeardownTest() { 41 require.NoError(suite.T(), os.Chdir(TempDir)) 42 } 43 44 // In order for 'go test' to run this suite, we need to create 45 // a normal test function and pass our suite to suite.Run 46 func TestInitTestSuite(t *testing.T) { 47 suite.Run(t, new(InitTestSuite)) 48 }