Repository: supabase/cli
Pull request #312 (2022-07-25 03:25:09)

test: secret list command
## What kind of change does this PR introduce?

unit test, refactor

## What is the current behavior?

Please link any relevant issues here.

## What is the new behavior?

- starts moving static file paths to `utils` package
- secret list: 85.7% coverage

## Additional context

Add any other context or screenshots.



Patch:
diff --git a/cmd/orgs.go b/cmd/orgs.go
index 59fa80d9..5c1c0345 100644
--- a/cmd/orgs.go
+++ b/cmd/orgs.go
@@ -1,6 +1,7 @@
 package cmd
 
 import (
+	"github.com/spf13/afero"
 	"github.com/spf13/cobra"
 	"github.com/supabase/cli/internal/orgs/list"
 )
@@ -15,7 +16,7 @@ var (
 		Use:   "list",
 		Short: "List all organizations the logged-in user belongs.",
 		RunE: func(cmd *cobra.Command, args []string) error {
-			return list.Run()
+			return list.Run(afero.NewOsFs())
 		},
 	}
 )
diff --git a/cmd/secrets.go b/cmd/secrets.go
index 29f68abf..db62e02e 100644
--- a/cmd/secrets.go
+++ b/cmd/secrets.go
@@ -1,6 +1,7 @@
 package cmd
 
 import (
+	"github.com/spf13/afero"
 	"github.com/spf13/cobra"
 	"github.com/supabase/cli/internal/secrets/list"
 	"github.com/supabase/cli/internal/secrets/set"
@@ -17,7 +18,7 @@ var (
 		Use:   "list",
 		Short: "List all secrets in the linked project.",
 		RunE: func(cmd *cobra.Command, args []string) error {
-			return list.Run()
+			return list.Run(afero.NewOsFs())
 		},
 	}
 
diff --git a/internal/db/remote/set/set.go b/internal/db/remote/set/set.go
index 00fdf99e..6a92e34c 100644
--- a/internal/db/remote/set/set.go
+++ b/internal/db/remote/set/set.go
@@ -45,7 +45,7 @@ func Run(url string) error {
 			dbMajorVersion,
 			utils.Config.Db.MajorVersion,
 			utils.Aqua("db.major_version"),
-			utils.Bold("supabase/config.toml"),
+			utils.Bold(utils.ConfigPath),
 		)
 	}
 
diff --git a/internal/functions/delete/delete.go b/internal/functions/delete/delete.go
index 4c69f4d0..d70a5f55 100644
--- a/internal/functions/delete/delete.go
+++ b/internal/functions/delete/delete.go
@@ -45,7 +45,7 @@ func Run(slug string, projectRefArg string) error {
 	{
 		// --project-ref overrides value on disk
 		if len(projectRefArg) == 0 {
-			projectRefBytes, err := os.ReadFile("supabase/.temp/project-ref")
+			projectRefBytes, err := os.ReadFile(utils.ProjectRefPath)
 			if err != nil {
 				return err
 			}
diff --git a/internal/functions/deploy/deploy.go b/internal/functions/deploy/deploy.go
index b7ad1213..0f50587d 100644
--- a/internal/functions/deploy/deploy.go
+++ b/internal/functions/deploy/deploy.go
@@ -45,7 +45,7 @@ Enter your project ref: `, utils.GetSupabaseDashboardURL())
 				if err := utils.MkdirIfNotExist("supabase/.temp"); err != nil {
 					return err
 				}
-				if err := os.WriteFile("supabase/.temp/project-ref", []byte(projectRef), 0644); err != nil {
+				if err := os.WriteFile(utils.ProjectRefPath, []byte(projectRef), 0644); err != nil {
 					return err
 				}
 			} else if err != nil {
@@ -108,7 +108,7 @@ Enter your project ref: `, utils.GetSupabaseDashboardURL())
 	{
 		// --project-ref overrides value on disk
 		if len(projectRefArg) == 0 {
-			projectRefBytes, err := os.ReadFile("supabase/.temp/project-ref")
+			projectRefBytes, err := os.ReadFile(utils.ProjectRefPath)
 			if err != nil {
 				return err
 			}
diff --git a/internal/gen/types/typescript/typescript.go b/internal/gen/types/typescript/typescript.go
index 4fbf5e7b..f13b8e50 100644
--- a/internal/gen/types/typescript/typescript.go
+++ b/internal/gen/types/typescript/typescript.go
@@ -78,7 +78,7 @@ func Run(isLocal bool, dbUrl string) error {
 			if err := utils.AssertIsLinked(); err != nil {
 				return err
 			}
-			projectRefBytes, err := os.ReadFile("supabase/.temp/project-ref")
+			projectRefBytes, err := os.ReadFile(utils.ProjectRefPath)
 			if err != nil {
 				return err
 			}
diff --git a/internal/init/init.go b/internal/init/init.go
index 542c7ba1..f2776136 100644
--- a/internal/init/init.go
+++ b/internal/init/init.go
@@ -36,7 +36,7 @@ func Run(fsys afero.Fs) error {
 func run(fsys afero.Fs) error {
 	// Sanity checks.
 	{
-		if _, err := fsys.Stat("supabase/config.toml"); err == nil {
+		if _, err := fsys.Stat(utils.ConfigPath); err == nil {
 			return errAlreadyInitialized
 		} else if !errors.Is(err, os.ErrNotExist) {
 			return err
diff --git a/internal/link/link.go b/internal/link/link.go
index d766efb4..db82e34c 100644
--- a/internal/link/link.go
+++ b/internal/link/link.go
@@ -51,7 +51,7 @@ func Run(projectRef string, fsys afero.Fs) error {
 		if err := utils.MkdirIfNotExistFS(fsys, "supabase/.temp"); err != nil {
 			return err
 		}
-		if err := afero.WriteFile(fsys, "supabase/.temp/project-ref", []byte(projectRef), 0644); err != nil {
+		if err := afero.WriteFile(fsys, utils.ProjectRefPath, []byte(projectRef), 0644); err != nil {
 			return err
 		}
 	}
diff --git a/internal/orgs/list/list.go b/internal/orgs/list/list.go
index 94ccac31..8eda9d2a 100644
--- a/internal/orgs/list/list.go
+++ b/internal/orgs/list/list.go
@@ -9,11 +9,17 @@ import (
 	"strings"
 
 	"github.com/charmbracelet/glamour"
+	"github.com/spf13/afero"
 	"github.com/supabase/cli/internal/utils"
 )
 
-func Run() error {
-	accessToken, err := utils.LoadAccessToken()
+type Organization struct {
+	Id   string `json:"id"`
+	Name string `json:"name"`
+}
+
+func Run(fsys afero.Fs) error {
+	accessToken, err := utils.LoadAccessTokenFS(fsys)
 	if err != nil {
 		return err
 	}
@@ -43,10 +49,7 @@ func Run() error {
 		return err
 	}
 
-	var orgs []struct {
-		Id   string `json:"id"`
-		Name string `json:"name"`
-	}
+	var orgs []Organization
 	if err := json.Unmarshal(body, &orgs); err != nil {
 		return err
 	}
diff --git a/internal/secrets/list/list.go b/internal/secrets/list/list.go
index 20d5f221..de3a293d 100644
--- a/internal/secrets/list/list.go
+++ b/internal/secrets/list/list.go
@@ -7,33 +7,38 @@ import (
 	"fmt"
 	"io"
 	"net/http"
-	"os"
 	"strings"
 
 	"github.com/charmbracelet/glamour"
+	"github.com/spf13/afero"
 	"github.com/supabase/cli/internal/utils"
 )
 
-func Run() error {
+type Secret struct {
+	Name  string
+	Value string
+}
+
+func Run(fsys afero.Fs) error {
 	// 1. Sanity checks.
 	{
-		if err := utils.AssertSupabaseCliIsSetUp(); err != nil {
+		if err := utils.AssertSupabaseCliIsSetUpFS(fsys); err != nil {
 			return err
 		}
-		if err := utils.AssertIsLinked(); err != nil {
+		if err := utils.AssertIsLinkedFS(fsys); err != nil {
 			return err
 		}
 	}
 
 	// 2. Print secrets.
 	{
-		projectRefBytes, err := os.ReadFile("supabase/.temp/project-ref")
+		projectRefBytes, err := afero.ReadFile(fsys, utils.ProjectRefPath)
 		if err != nil {
 			return err
 		}
 		projectRef := string(projectRefBytes)
 
-		accessToken, err := utils.LoadAccessToken()
+		accessToken, err := utils.LoadAccessTokenFS(fsys)
 		if err != nil {
 			return err
 		}
@@ -63,10 +68,7 @@ func Run() error {
 			return err
 		}
 
-		var secrets []struct {
-			Name  string
-			Value string
-		}
+		var secrets []Secret
 		if err := json.Unmarshal(body, &secrets); err != nil {
 			return err
 		}
diff --git a/internal/secrets/set/set.go b/internal/secrets/set/set.go
index dcc16346..5dc9373a 100644
--- a/internal/secrets/set/set.go
+++ b/internal/secrets/set/set.go
@@ -27,7 +27,7 @@ func Run(envFilePath string, args []string) error {
 
 	// 2. Set secret(s).
 	{
-		projectRefBytes, err := os.ReadFile("supabase/.temp/project-ref")
+		projectRefBytes, err := os.ReadFile(utils.ProjectRefPath)
 		if err != nil {
 			return err
 		}
diff --git a/internal/secrets/unset/unset.go b/internal/secrets/unset/unset.go
index c0137c0d..79afb5c8 100644
--- a/internal/secrets/unset/unset.go
+++ b/internal/secrets/unset/unset.go
@@ -25,7 +25,7 @@ func Run(args []string) error {
 
 	// 2. Unset secret(s).
 	{
-		projectRefBytes, err := os.ReadFile("supabase/.temp/project-ref")
+		projectRefBytes, err := os.ReadFile(utils.ProjectRefPath)
 		if err != nil {
 			return err
 		}
diff --git a/internal/utils/config.go b/internal/utils/config.go
index 30a87456..93c93295 100644
--- a/internal/utils/config.go
+++ b/internal/utils/config.go
@@ -131,7 +131,7 @@ func LoadConfig() error {
 
 func loadConfig(fsys afero.Fs) error {
 	// TODO: provide a config interface for all sub commands to use fsys
-	if _, err := toml.DecodeFS(afero.NewIOFS(fsys), "supabase/config.toml", &Config); err == nil {
+	if _, err := toml.DecodeFS(afero.NewIOFS(fsys), ConfigPath, &Config); err == nil {
 		// skip
 	} else if errors.Is(err, os.ErrNotExist) {
 		_, _err := os.Stat("supabase/config.json")
@@ -384,7 +384,7 @@ secret = ""
 	Config.Db.MajorVersion = uint(dbMajorVersion)
 	Config.Auth.SiteUrl = "http://localhost:3000"
 
-	if err := os.WriteFile("supabase/config.toml", []byte(newConfig), 0644); err != nil {
+	if err := os.WriteFile(ConfigPath, []byte(newConfig), 0644); err != nil {
 		return err
 	}
 	if err := os.Remove("supabase/config.json"); err != nil {
@@ -417,7 +417,7 @@ func WriteConfig(fsys afero.Fs, test bool) error {
 		return err
 	}
 
-	if err := afero.WriteFile(fsys, "supabase/config.toml", initConfigBuf.Bytes(), 0644); err != nil {
+	if err := afero.WriteFile(fsys, ConfigPath, initConfigBuf.Bytes(), 0644); err != nil {
 		return err
 	}
 
diff --git a/internal/utils/misc.go b/internal/utils/misc.go
index 503dcbc6..a1276d9f 100644
--- a/internal/utils/misc.go
+++ b/internal/utils/misc.go
@@ -49,6 +49,9 @@ DO 'BEGIN WHILE (SELECT COUNT(*) FROM pg_replication_slots) > 0 LOOP END LOOP; E
 `
 	AnonKey        = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24ifQ.625_WdcF3KHqz5amU0x2X5WWHP-OEs_4qj0ssLNHzTs"
 	ServiceRoleKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSJ9.vI9obAHOGyVVKa3pD--kJlyxp-Z2zV9UUMAhKpNLAcU"
+
+	ConfigPath     = "supabase/config.toml"
+	ProjectRefPath = "supabase/.temp/project-ref"
 )
 
 var (
@@ -171,8 +174,12 @@ func MkdirIfNotExistFS(fsys afero.Fs, path string) error {
 }
 
 func AssertSupabaseCliIsSetUp() error {
-	if _, err := os.ReadFile("supabase/config.toml"); errors.Is(err, os.ErrNotExist) {
-		return errors.New("Cannot find " + Bold("supabase/config.toml") + " in the current directory. Have you set up the project with " + Aqua("supabase init") + "?")
+	return AssertSupabaseCliIsSetUpFS(afero.NewOsFs())
+}
+
+func AssertSupabaseCliIsSetUpFS(fsys afero.Fs) error {
+	if _, err := fsys.Stat(ConfigPath); errors.Is(err, os.ErrNotExist) {
+		return errors.New("Cannot find " + Bold(ConfigPath) + " in the current directory. Have you set up the project with " + Aqua("supabase init") + "?")
 	} else if err != nil {
 		return err
 	}
@@ -181,7 +188,11 @@ func AssertSupabaseCliIsSetUp() error {
 }
 
 func AssertIsLinked() error {
-	if _, err := os.Stat("supabase/.temp/project-ref"); errors.Is(err, os.ErrNotExist) {
+	return AssertIsLinkedFS(afero.NewOsFs())
+}
+
+func AssertIsLinkedFS(fsys afero.Fs) error {
+	if _, err := fsys.Stat(ProjectRefPath); errors.Is(err, os.ErrNotExist) {
 		return errors.New("Cannot find project ref. Have you run " + Aqua("supabase link") + "?")
 	} else if err != nil {
 		return err


Test patch:
diff --git a/internal/init/init_test.go b/internal/init/init_test.go
index 9f7a3fca..5a36fd91 100644
--- a/internal/init/init_test.go
+++ b/internal/init/init_test.go
@@ -23,7 +23,7 @@ func TestInitCommand(t *testing.T) {
 		// Run test
 		assert.NoError(t, Run(fsys))
 		// Validate generated config.toml
-		exists, err := afero.Exists(fsys, "supabase/config.toml")
+		exists, err := afero.Exists(fsys, utils.ConfigPath)
 		assert.NoError(t, err)
 		assert.True(t, exists)
 		// Validate generated .gitignore
@@ -35,7 +35,7 @@ func TestInitCommand(t *testing.T) {
 	t.Run("throws error when config file exists", func(t *testing.T) {
 		// Setup in-memory fs
 		fsys := &afero.MemMapFs{}
-		_, err := fsys.Create("supabase/config.toml")
+		_, err := fsys.Create(utils.ConfigPath)
 		require.NoError(t, err)
 		// Run test
 		assert.Error(t, Run(fsys))
diff --git a/internal/link/link_test.go b/internal/link/link_test.go
index afa314ea..dd04a272 100644
--- a/internal/link/link_test.go
+++ b/internal/link/link_test.go
@@ -7,6 +7,7 @@ import (
 	"github.com/spf13/afero"
 	"github.com/stretchr/testify/assert"
 	"github.com/supabase/cli/internal/testing/apitest"
+	"github.com/supabase/cli/internal/utils"
 	"gopkg.in/h2non/gock.v1"
 )
 
@@ -26,6 +27,10 @@ func TestLinkCommand(t *testing.T) {
 			JSON([]string{})
 		// Run test
 		assert.NoError(t, Run(project, fsys))
+		// Validate file contents
+		content, err := afero.ReadFile(fsys, utils.ProjectRefPath)
+		assert.NoError(t, err)
+		assert.Equal(t, []byte(project), content)
 	})
 
 	t.Run("throws error on invalid project ref", func(t *testing.T) {
diff --git a/internal/orgs/list/list_test.go b/internal/orgs/list/list_test.go
new file mode 100644
index 00000000..944e0698
--- /dev/null
+++ b/internal/orgs/list/list_test.go
@@ -0,0 +1,85 @@
+package list
+
+import (
+	"errors"
+	"testing"
+
+	"github.com/spf13/afero"
+	"github.com/stretchr/testify/assert"
+	"github.com/supabase/cli/internal/testing/apitest"
+	"gopkg.in/h2non/gock.v1"
+)
+
+func TestOrganizationListCommand(t *testing.T) {
+	t.Run("lists all organizations", func(t *testing.T) {
+		// Setup in-memory fs
+		fsys := afero.NewMemMapFs()
+		// Setup valid access token
+		token := apitest.RandomAccessToken(t)
+		t.Setenv("SUPABASE_ACCESS_TOKEN", string(token))
+		// Flush pending mocks after test execution
+		defer gock.Off()
+		gock.New("https://api.supabase.io").
+			Get("/v1/organizations").
+			Reply(200).
+			JSON([]Organization{
+				{
+					Id:   "combined-fuchsia-lion",
+					Name: "Test Organization",
+				},
+			})
+		// Run test
+		assert.NoError(t, Run(fsys))
+	})
+
+	t.Run("throws error on failure to load token", func(t *testing.T) {
+		assert.Error(t, Run(afero.NewMemMapFs()))
+	})
+
+	t.Run("throws error on network error", func(t *testing.T) {
+		// Setup in-memory fs
+		fsys := afero.NewMemMapFs()
+		// Setup valid access token
+		token := apitest.RandomAccessToken(t)
+		t.Setenv("SUPABASE_ACCESS_TOKEN", string(token))
+		// Flush pending mocks after test execution
+		defer gock.Off()
+		gock.New("https://api.supabase.io").
+			Get("/v1/organizations").
+			ReplyError(errors.New("network error"))
+		// Run test
+		assert.Error(t, Run(fsys))
+	})
+
+	t.Run("throws error on server unavailable", func(t *testing.T) {
+		// Setup in-memory fs
+		fsys := afero.NewMemMapFs()
+		// Setup valid access token
+		token := apitest.RandomAccessToken(t)
+		t.Setenv("SUPABASE_ACCESS_TOKEN", string(token))
+		// Flush pending mocks after test execution
+		defer gock.Off()
+		gock.New("https://api.supabase.io").
+			Get("/v1/organizations").
+			Reply(500).
+			JSON(map[string]string{"message": "unavailable"})
+		// Run test
+		assert.Error(t, Run(fsys))
+	})
+
+	t.Run("throws error on malformed json", func(t *testing.T) {
+		// Setup in-memory fs
+		fsys := afero.NewMemMapFs()
+		// Setup valid access token
+		token := apitest.RandomAccessToken(t)
+		t.Setenv("SUPABASE_ACCESS_TOKEN", string(token))
+		// Flush pending mocks after test execution
+		defer gock.Off()
+		gock.New("https://api.supabase.io").
+			Get("/v1/organizations").
+			Reply(200).
+			JSON(map[string]string{})
+		// Run test
+		assert.Error(t, Run(fsys))
+	})
+}
diff --git a/internal/secrets/list/list_test.go b/internal/secrets/list/list_test.go
new file mode 100644
index 00000000..cd5d5e47
--- /dev/null
+++ b/internal/secrets/list/list_test.go
@@ -0,0 +1,131 @@
+package list
+
+import (
+	"errors"
+	"testing"
+
+	"github.com/spf13/afero"
+	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
+	"github.com/supabase/cli/internal/testing/apitest"
+	"github.com/supabase/cli/internal/utils"
+	"gopkg.in/h2non/gock.v1"
+)
+
+func TestSecretListCommand(t *testing.T) {
+	t.Run("lists all secrets", func(t *testing.T) {
+		// Setup in-memory fs
+		fsys := afero.NewMemMapFs()
+		_, err := fsys.Create(utils.ConfigPath)
+		require.NoError(t, err)
+		// Setup valid project ref
+		project := apitest.RandomProjectRef()
+		err = afero.WriteFile(fsys, utils.ProjectRefPath, []byte(project), 0644)
+		require.NoError(t, err)
+		// Setup valid access token
+		token := apitest.RandomAccessToken(t)
+		t.Setenv("SUPABASE_ACCESS_TOKEN", string(token))
+		// Flush pending mocks after test execution
+		defer gock.Off()
+		gock.New("https://api.supabase.io").
+			Get("/v1/projects/" + project + "/secrets").
+			Reply(200).
+			JSON([]Secret{
+				{
+					Name:  "Test Secret",
+					Value: "dummy-secret-value",
+				},
+			})
+		// Run test
+		assert.NoError(t, Run(fsys))
+	})
+
+	t.Run("throws error on missing config file", func(t *testing.T) {
+		assert.Error(t, Run(afero.NewMemMapFs()))
+	})
+
+	t.Run("throws error on missing project ref", func(t *testing.T) {
+		// Setup in-memory fs
+		fsys := afero.NewMemMapFs()
+		_, err := fsys.Create(utils.ConfigPath)
+		require.NoError(t, err)
+		// Run test
+		assert.Error(t, Run(fsys))
+	})
+
+	t.Run("throws error on missing access token", func(t *testing.T) {
+		// Setup in-memory fs
+		fsys := afero.NewMemMapFs()
+		_, err := fsys.Create(utils.ConfigPath)
+		require.NoError(t, err)
+		_, err = fsys.Create(utils.ProjectRefPath)
+		require.NoError(t, err)
+		// Run test
+		assert.Error(t, Run(fsys))
+	})
+
+	t.Run("throws error on network error", func(t *testing.T) {
+		// Setup in-memory fs
+		fsys := afero.NewMemMapFs()
+		_, err := fsys.Create(utils.ConfigPath)
+		require.NoError(t, err)
+		// Setup valid project ref
+		project := apitest.RandomProjectRef()
+		err = afero.WriteFile(fsys, utils.ProjectRefPath, []byte(project), 0644)
+		require.NoError(t, err)
+		// Setup valid access token
+		token := apitest.RandomAccessToken(t)
+		t.Setenv("SUPABASE_ACCESS_TOKEN", string(token))
+		// Flush pending mocks after test execution
+		defer gock.Off()
+		gock.New("https://api.supabase.io").
+			Get("/v1/projects/" + project + "/secrets").
+			ReplyError(errors.New("network error"))
+		// Run test
+		assert.Error(t, Run(fsys))
+	})
+
+	t.Run("throws error on server unavailable", func(t *testing.T) {
+		// Setup in-memory fs
+		fsys := afero.NewMemMapFs()
+		_, err := fsys.Create(utils.ConfigPath)
+		require.NoError(t, err)
+		// Setup valid project ref
+		project := apitest.RandomProjectRef()
+		err = afero.WriteFile(fsys, utils.ProjectRefPath, []byte(project), 0644)
+		require.NoError(t, err)
+		// Setup valid access token
+		token := apitest.RandomAccessToken(t)
+		t.Setenv("SUPABASE_ACCESS_TOKEN", string(token))
+		// Flush pending mocks after test execution
+		defer gock.Off()
+		gock.New("https://api.supabase.io").
+			Get("/v1/projects/" + project + "/secrets").
+			Reply(500).
+			JSON(map[string]string{"message": "unavailable"})
+		// Run test
+		assert.Error(t, Run(fsys))
+	})
+
+	t.Run("throws error on malformed json", func(t *testing.T) {
+		// Setup in-memory fs
+		fsys := afero.NewMemMapFs()
+		_, err := fsys.Create(utils.ConfigPath)
+		require.NoError(t, err)
+		// Setup valid project ref
+		project := apitest.RandomProjectRef()
+		err = afero.WriteFile(fsys, utils.ProjectRefPath, []byte(project), 0644)
+		require.NoError(t, err)
+		// Setup valid access token
+		token := apitest.RandomAccessToken(t)
+		t.Setenv("SUPABASE_ACCESS_TOKEN", string(token))
+		// Flush pending mocks after test execution
+		defer gock.Off()
+		gock.New("https://api.supabase.io").
+			Get("/v1/projects/" + project + "/secrets").
+			Reply(200).
+			JSON(map[string]string{})
+		// Run test
+		assert.Error(t, Run(fsys))
+	})
+}
diff --git a/test/init_test.go b/test/init_test.go
index 2d439c17..0a49c4d6 100644
--- a/test/init_test.go
+++ b/test/init_test.go
@@ -9,6 +9,7 @@ import (
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 	clicmd "github.com/supabase/cli/cmd"
+	"github.com/supabase/cli/internal/utils"
 )
 
 type InitTestSuite struct {
@@ -25,7 +26,7 @@ func (suite *InitTestSuite) TestInit() {
 	require.NoError(suite.T(), init.RunE(init, []string{}))
 
 	// check if init dir exists
-	_, err = os.Stat("supabase/config.toml")
+	_, err = os.Stat(utils.ConfigPath)
 	require.NoError(suite.T(), err)
 }
 
diff --git a/test/link_test.go b/test/link_test.go
index cc712883..87a6244a 100644
--- a/test/link_test.go
+++ b/test/link_test.go
@@ -15,6 +15,7 @@ import (
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 	clicmd "github.com/supabase/cli/cmd"
+	"github.com/supabase/cli/internal/utils"
 	"github.com/supabase/cli/test/mocks/supabase"
 )
 
@@ -49,9 +50,9 @@ func (suite *LinkTestSuite) TestLink() {
 		"Accept-Encoding": []string{"gzip"},
 		"User-Agent":      []string{"Go-http-client/1.1"},
 	})
-	_, err = os.Stat("supabase/.temp/project-ref")
+	_, err = os.Stat(utils.ProjectRefPath)
 	require.NoError(suite.T(), err)
-	ref, err := ioutil.ReadFile("supabase/.temp/project-ref")
+	ref, err := ioutil.ReadFile(utils.ProjectRefPath)
 	require.NoError(suite.T(), err)
 	require.Equal(suite.T(), id, string(ref))
 }
diff --git a/test/secrets_test.go b/test/secrets_test.go
index e87f1415..f67bad34 100644
--- a/test/secrets_test.go
+++ b/test/secrets_test.go
@@ -15,6 +15,7 @@ import (
 	"github.com/stretchr/testify/require"
 	"github.com/stretchr/testify/suite"
 	clicmd "github.com/supabase/cli/cmd"
+	"github.com/supabase/cli/internal/utils"
 	"github.com/supabase/cli/test/mocks/supabase"
 )
 
@@ -38,7 +39,7 @@ func (suite *SecretsTestSuite) TestLink() {
 	key := "sbp_" + gonanoid.MustGenerate(supabase.KeyAlphabet, supabase.KeyLength)
 	os.Setenv("SUPABASE_ACCESS_TOKEN", key)
 	ref := gonanoid.MustGenerate(supabase.IDAlphabet, supabase.IDLength)
-	require.NoError(suite.T(), ioutil.WriteFile("supabase/.temp/project-ref", []byte(ref), os.FileMode(0755)))
+	require.NoError(suite.T(), ioutil.WriteFile(utils.ProjectRefPath, []byte(ref), os.FileMode(0755)))
 
 	// set stdout to write into file so we can capture cmd output
 	tmpfile, err := ioutil.TempFile(suite.tempDir, "output")