Skip to content

Commit 337558d

Browse files
refactor: centralize project paths
1 parent 88d67d4 commit 337558d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+387
-354
lines changed

internal/bootstrap/bootstrap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func Run(ctx context.Context, starter StarterTemplate, fsys afero.Fs, options ..
100100
return err
101101
}
102102
link.LinkServices(ctx, flags.ProjectRef, tenant.NewApiKey(keys).Anon, false, fsys)
103-
if err := utils.WriteFile(utils.ProjectRefPath, []byte(flags.ProjectRef), fsys); err != nil {
103+
if err := utils.WriteFile(utils.Paths.ProjectRefPath, []byte(flags.ProjectRef), fsys); err != nil {
104104
return err
105105
}
106106
// 5. Wait for project healthy

internal/branches/create/create_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestCreateCommand(t *testing.T) {
4747
t.Run("throws error on network disconnected", func(t *testing.T) {
4848
// Setup in-memory fs
4949
fsys := afero.NewMemMapFs()
50-
require.NoError(t, afero.WriteFile(fsys, utils.ProjectRefPath, []byte(flags.ProjectRef), 0644))
50+
require.NoError(t, afero.WriteFile(fsys, utils.Paths.ProjectRefPath, []byte(flags.ProjectRef), 0644))
5151
// Setup mock api
5252
defer gock.OffAll()
5353
gock.New(utils.DefaultApiHost).
@@ -64,7 +64,7 @@ func TestCreateCommand(t *testing.T) {
6464
t.Run("throws error on service unavailable", func(t *testing.T) {
6565
// Setup in-memory fs
6666
fsys := afero.NewMemMapFs()
67-
require.NoError(t, afero.WriteFile(fsys, utils.ProjectRefPath, []byte(flags.ProjectRef), 0644))
67+
require.NoError(t, afero.WriteFile(fsys, utils.Paths.ProjectRefPath, []byte(flags.ProjectRef), 0644))
6868
// Setup mock api
6969
defer gock.OffAll()
7070
gock.New(utils.DefaultApiHost).

internal/config/push/push_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestPushConfig(t *testing.T) {
2323
t.Run("throws error on malformed config", func(t *testing.T) {
2424
// Setup in-memory fs
2525
fsys := afero.NewMemMapFs()
26-
require.NoError(t, utils.WriteFile(utils.ConfigPath, []byte("malformed"), fsys))
26+
require.NoError(t, utils.WriteFile(utils.Paths.ConfigPath, []byte("malformed"), fsys))
2727
// Run test
2828
err := Run(context.Background(), "", fsys)
2929
// Check error

internal/db/branch/create/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func Run(branch string, fsys afero.Fs) error {
3030
return err
3131
}
3232

33-
branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), branch)
33+
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), branch)
3434
if err := assertNewBranchIsValid(branchPath, fsys); err != nil {
3535
return nil
3636
}

internal/db/branch/delete/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func deleteBranchDir(branch string, fsys afero.Fs) error {
4646
return errors.New("Cannot delete branch " + utils.Aqua(branch) + ": branch name is reserved.")
4747
}
4848

49-
branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), branch)
49+
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), branch)
5050
if _, err := afero.ReadDir(fsys, branchPath); err != nil {
5151
return errors.New("Branch " + utils.Aqua(branch) + " does not exist.")
5252
}

internal/db/branch/delete/delete_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestBranchDir(t *testing.T) {
1717
t.Run("removes a branch directory", func(t *testing.T) {
1818
// Setup in-memory fs
1919
fsys := afero.NewMemMapFs()
20-
path := filepath.Join(filepath.Dir(utils.CurrBranchPath), "test-branch")
20+
path := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), "test-branch")
2121
require.NoError(t, fsys.Mkdir(path, 0755))
2222
// Run test
2323
assert.NoError(t, deleteBranchDir("test-branch", fsys))
@@ -30,7 +30,7 @@ func TestBranchDir(t *testing.T) {
3030
t.Run("branch is current", func(t *testing.T) {
3131
// Setup in-memory fs
3232
fsys := afero.NewMemMapFs()
33-
require.NoError(t, afero.WriteFile(fsys, utils.CurrBranchPath, []byte("main"), 0644))
33+
require.NoError(t, afero.WriteFile(fsys, utils.Paths.CurrBranchPath, []byte("main"), 0644))
3434
// Run test
3535
assert.Error(t, deleteBranchDir("main", fsys))
3636
})
@@ -46,7 +46,7 @@ func TestBranchDir(t *testing.T) {
4646
t.Run("branch permission denied", func(t *testing.T) {
4747
// Setup read-only fs
4848
fsys := afero.NewMemMapFs()
49-
path := filepath.Join(filepath.Dir(utils.CurrBranchPath), "test-branch")
49+
path := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), "test-branch")
5050
require.NoError(t, fsys.Mkdir(path, 0755))
5151
// Run test
5252
assert.Error(t, deleteBranchDir("test-branch", afero.NewReadOnlyFs(fsys)))

internal/db/branch/list/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func Run(fsys afero.Fs, out io.Writer) error {
15-
branches, err := afero.ReadDir(fsys, filepath.Dir(utils.CurrBranchPath))
15+
branches, err := afero.ReadDir(fsys, filepath.Dir(utils.Paths.CurrBranchPath))
1616
if errors.Is(err, os.ErrNotExist) {
1717
return nil
1818
} else if err != nil {
@@ -21,7 +21,7 @@ func Run(fsys afero.Fs, out io.Writer) error {
2121

2222
currBranch, _ := utils.GetCurrentBranchFS(fsys)
2323
for _, branch := range branches {
24-
if branch.Name() == filepath.Base(utils.CurrBranchPath) {
24+
if branch.Name() == filepath.Base(utils.Paths.CurrBranchPath) {
2525
continue
2626
}
2727

internal/db/branch/list/list_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ func TestListCommand(t *testing.T) {
1717
t.Run("lists all branches", func(t *testing.T) {
1818
// Setup in-memory fs
1919
fsys := afero.NewMemMapFs()
20-
require.NoError(t, afero.WriteFile(fsys, utils.CurrBranchPath, []byte("main"), 0644))
21-
base := filepath.Dir(utils.CurrBranchPath)
20+
require.NoError(t, afero.WriteFile(fsys, utils.Paths.CurrBranchPath, []byte("main"), 0644))
21+
base := filepath.Dir(utils.Paths.CurrBranchPath)
2222
require.NoError(t, fsys.Mkdir(filepath.Join(base, "main"), 0755))
2323
require.NoError(t, fsys.Mkdir(filepath.Join(base, "test"), 0755))
2424
// Run test
@@ -36,7 +36,7 @@ func TestListCommand(t *testing.T) {
3636
t.Run("lists without current branch", func(t *testing.T) {
3737
// Setup in-memory fs
3838
fsys := afero.NewMemMapFs()
39-
base := filepath.Dir(utils.CurrBranchPath)
39+
base := filepath.Dir(utils.Paths.CurrBranchPath)
4040
require.NoError(t, fsys.Mkdir(filepath.Join(base, "main"), 0755))
4141
require.NoError(t, fsys.Mkdir(filepath.Join(base, "test"), 0755))
4242
// Run test
@@ -58,7 +58,7 @@ func TestListCommand(t *testing.T) {
5858
t.Run("throws error on unreadable directory", func(t *testing.T) {
5959
// Setup in-memory fs
6060
fsys := afero.NewMemMapFs()
61-
_, err := fsys.Create(filepath.Dir(utils.CurrBranchPath))
61+
_, err := fsys.Create(filepath.Dir(utils.Paths.CurrBranchPath))
6262
require.NoError(t, err)
6363
// Run test
6464
require.Error(t, Run(fsys, io.Discard))

internal/db/branch/switch_/switch_.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func Run(ctx context.Context, target string, fsys afero.Fs, options ...func(*pgx
2727
if target != "main" && utils.IsBranchNameReserved(target) {
2828
return errors.New("Cannot switch branch " + utils.Aqua(target) + ": branch name is reserved.")
2929
}
30-
branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), target)
30+
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), target)
3131
if _, err := fsys.Stat(branchPath); errors.Is(err, os.ErrNotExist) {
3232
return errors.New("Branch " + utils.Aqua(target) + " does not exist.")
3333
} else if err != nil {
@@ -52,8 +52,8 @@ func Run(ctx context.Context, target string, fsys afero.Fs, options ...func(*pgx
5252
}
5353

5454
// 4. Update current branch
55-
if err := afero.WriteFile(fsys, utils.CurrBranchPath, []byte(target), 0644); err != nil {
56-
return errors.New("Unable to update local branch file. Fix by running: echo '" + target + "' > " + utils.CurrBranchPath)
55+
if err := afero.WriteFile(fsys, utils.Paths.CurrBranchPath, []byte(target), 0644); err != nil {
56+
return errors.New("Unable to update local branch file. Fix by running: echo '" + target + "' > " + utils.Paths.CurrBranchPath)
5757
}
5858
return nil
5959
}

internal/db/branch/switch_/switch__test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ func TestSwitchCommand(t *testing.T) {
2525
require.NoError(t, utils.WriteConfig(fsys, false))
2626
// Setup target branch
2727
branch := "target"
28-
branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), branch)
28+
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), branch)
2929
require.NoError(t, fsys.Mkdir(branchPath, 0755))
30-
require.NoError(t, afero.WriteFile(fsys, utils.CurrBranchPath, []byte("main"), 0644))
30+
require.NoError(t, afero.WriteFile(fsys, utils.Paths.CurrBranchPath, []byte("main"), 0644))
3131
// Setup mock docker
3232
require.NoError(t, apitest.MockDocker(utils.Docker))
3333
defer gock.OffAll()
@@ -57,15 +57,15 @@ func TestSwitchCommand(t *testing.T) {
5757
assert.NoError(t, Run(context.Background(), branch, fsys, conn.Intercept))
5858
// Validate output
5959
assert.Empty(t, apitest.ListUnmatchedRequests())
60-
contents, err := afero.ReadFile(fsys, utils.CurrBranchPath)
60+
contents, err := afero.ReadFile(fsys, utils.Paths.CurrBranchPath)
6161
assert.NoError(t, err)
6262
assert.Equal(t, []byte(branch), contents)
6363
})
6464

6565
t.Run("throws error on malformed config", func(t *testing.T) {
6666
// Setup in-memory fs
6767
fsys := afero.NewMemMapFs()
68-
require.NoError(t, afero.WriteFile(fsys, utils.ConfigPath, []byte("malformed"), 0644))
68+
require.NoError(t, afero.WriteFile(fsys, utils.Paths.ConfigPath, []byte("malformed"), 0644))
6969
// Run test
7070
err := Run(context.Background(), "target", fsys)
7171
// Check error
@@ -138,13 +138,13 @@ func TestSwitchCommand(t *testing.T) {
138138
JSON(container.InspectResponse{})
139139
// Setup target branch
140140
branch := "main"
141-
branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), branch)
141+
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), branch)
142142
require.NoError(t, fsys.Mkdir(branchPath, 0755))
143143
// Run test
144144
assert.NoError(t, Run(context.Background(), branch, fsys))
145145
// Check error
146146
assert.Empty(t, apitest.ListUnmatchedRequests())
147-
contents, err := afero.ReadFile(fsys, utils.CurrBranchPath)
147+
contents, err := afero.ReadFile(fsys, utils.Paths.CurrBranchPath)
148148
assert.NoError(t, err)
149149
assert.Equal(t, []byte(branch), contents)
150150
})
@@ -162,7 +162,7 @@ func TestSwitchCommand(t *testing.T) {
162162
JSON(container.InspectResponse{})
163163
// Setup target branch
164164
branch := "target"
165-
branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), branch)
165+
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), branch)
166166
require.NoError(t, fsys.Mkdir(branchPath, 0755))
167167
// Setup mock postgres
168168
conn := pgtest.NewConn()
@@ -186,7 +186,7 @@ func TestSwitchCommand(t *testing.T) {
186186
JSON(container.InspectResponse{})
187187
// Setup target branch
188188
branch := "main"
189-
branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), branch)
189+
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), branch)
190190
require.NoError(t, fsys.Mkdir(branchPath, 0755))
191191
// Run test
192192
err := Run(context.Background(), branch, afero.NewReadOnlyFs(fsys))

0 commit comments

Comments
 (0)