Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func Run(ctx context.Context, starter StarterTemplate, fsys afero.Fs, options ..
return err
}
link.LinkServices(ctx, flags.ProjectRef, tenant.NewApiKey(keys).Anon, false, fsys)
if err := utils.WriteFile(utils.ProjectRefPath, []byte(flags.ProjectRef), fsys); err != nil {
if err := utils.WriteFile(utils.Paths.ProjectRefPath, []byte(flags.ProjectRef), fsys); err != nil {
return err
}
// 5. Wait for project healthy
Expand Down
4 changes: 2 additions & 2 deletions internal/branches/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestCreateCommand(t *testing.T) {
t.Run("throws error on network disconnected", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
require.NoError(t, afero.WriteFile(fsys, utils.ProjectRefPath, []byte(flags.ProjectRef), 0644))
require.NoError(t, afero.WriteFile(fsys, utils.Paths.ProjectRefPath, []byte(flags.ProjectRef), 0644))
// Setup mock api
defer gock.OffAll()
gock.New(utils.DefaultApiHost).
Expand All @@ -64,7 +64,7 @@ func TestCreateCommand(t *testing.T) {
t.Run("throws error on service unavailable", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
require.NoError(t, afero.WriteFile(fsys, utils.ProjectRefPath, []byte(flags.ProjectRef), 0644))
require.NoError(t, afero.WriteFile(fsys, utils.Paths.ProjectRefPath, []byte(flags.ProjectRef), 0644))
// Setup mock api
defer gock.OffAll()
gock.New(utils.DefaultApiHost).
Expand Down
2 changes: 1 addition & 1 deletion internal/config/push/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestPushConfig(t *testing.T) {
t.Run("throws error on malformed config", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
require.NoError(t, utils.WriteFile(utils.ConfigPath, []byte("malformed"), fsys))
require.NoError(t, utils.WriteFile(utils.Paths.ConfigPath, []byte("malformed"), fsys))
// Run test
err := Run(context.Background(), "", fsys)
// Check error
Expand Down
2 changes: 1 addition & 1 deletion internal/db/branch/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Run(branch string, fsys afero.Fs) error {
return err
}

branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), branch)
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), branch)
if err := assertNewBranchIsValid(branchPath, fsys); err != nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/db/branch/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func deleteBranchDir(branch string, fsys afero.Fs) error {
return errors.New("Cannot delete branch " + utils.Aqua(branch) + ": branch name is reserved.")
}

branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), branch)
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), branch)
if _, err := afero.ReadDir(fsys, branchPath); err != nil {
return errors.New("Branch " + utils.Aqua(branch) + " does not exist.")
}
Expand Down
6 changes: 3 additions & 3 deletions internal/db/branch/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestBranchDir(t *testing.T) {
t.Run("removes a branch directory", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
path := filepath.Join(filepath.Dir(utils.CurrBranchPath), "test-branch")
path := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), "test-branch")
require.NoError(t, fsys.Mkdir(path, 0755))
// Run test
assert.NoError(t, deleteBranchDir("test-branch", fsys))
Expand All @@ -30,7 +30,7 @@ func TestBranchDir(t *testing.T) {
t.Run("branch is current", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
require.NoError(t, afero.WriteFile(fsys, utils.CurrBranchPath, []byte("main"), 0644))
require.NoError(t, afero.WriteFile(fsys, utils.Paths.CurrBranchPath, []byte("main"), 0644))
// Run test
assert.Error(t, deleteBranchDir("main", fsys))
})
Expand All @@ -46,7 +46,7 @@ func TestBranchDir(t *testing.T) {
t.Run("branch permission denied", func(t *testing.T) {
// Setup read-only fs
fsys := afero.NewMemMapFs()
path := filepath.Join(filepath.Dir(utils.CurrBranchPath), "test-branch")
path := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), "test-branch")
require.NoError(t, fsys.Mkdir(path, 0755))
// Run test
assert.Error(t, deleteBranchDir("test-branch", afero.NewReadOnlyFs(fsys)))
Expand Down
4 changes: 2 additions & 2 deletions internal/db/branch/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

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

currBranch, _ := utils.GetCurrentBranchFS(fsys)
for _, branch := range branches {
if branch.Name() == filepath.Base(utils.CurrBranchPath) {
if branch.Name() == filepath.Base(utils.Paths.CurrBranchPath) {
continue
}

Expand Down
8 changes: 4 additions & 4 deletions internal/db/branch/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ func TestListCommand(t *testing.T) {
t.Run("lists all branches", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
require.NoError(t, afero.WriteFile(fsys, utils.CurrBranchPath, []byte("main"), 0644))
base := filepath.Dir(utils.CurrBranchPath)
require.NoError(t, afero.WriteFile(fsys, utils.Paths.CurrBranchPath, []byte("main"), 0644))
base := filepath.Dir(utils.Paths.CurrBranchPath)
require.NoError(t, fsys.Mkdir(filepath.Join(base, "main"), 0755))
require.NoError(t, fsys.Mkdir(filepath.Join(base, "test"), 0755))
// Run test
Expand All @@ -36,7 +36,7 @@ func TestListCommand(t *testing.T) {
t.Run("lists without current branch", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
base := filepath.Dir(utils.CurrBranchPath)
base := filepath.Dir(utils.Paths.CurrBranchPath)
require.NoError(t, fsys.Mkdir(filepath.Join(base, "main"), 0755))
require.NoError(t, fsys.Mkdir(filepath.Join(base, "test"), 0755))
// Run test
Expand All @@ -58,7 +58,7 @@ func TestListCommand(t *testing.T) {
t.Run("throws error on unreadable directory", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
_, err := fsys.Create(filepath.Dir(utils.CurrBranchPath))
_, err := fsys.Create(filepath.Dir(utils.Paths.CurrBranchPath))
require.NoError(t, err)
// Run test
require.Error(t, Run(fsys, io.Discard))
Expand Down
6 changes: 3 additions & 3 deletions internal/db/branch/switch_/switch_.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Run(ctx context.Context, target string, fsys afero.Fs, options ...func(*pgx
if target != "main" && utils.IsBranchNameReserved(target) {
return errors.New("Cannot switch branch " + utils.Aqua(target) + ": branch name is reserved.")
}
branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), target)
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), target)
if _, err := fsys.Stat(branchPath); errors.Is(err, os.ErrNotExist) {
return errors.New("Branch " + utils.Aqua(target) + " does not exist.")
} else if err != nil {
Expand All @@ -52,8 +52,8 @@ func Run(ctx context.Context, target string, fsys afero.Fs, options ...func(*pgx
}

// 4. Update current branch
if err := afero.WriteFile(fsys, utils.CurrBranchPath, []byte(target), 0644); err != nil {
return errors.New("Unable to update local branch file. Fix by running: echo '" + target + "' > " + utils.CurrBranchPath)
if err := afero.WriteFile(fsys, utils.Paths.CurrBranchPath, []byte(target), 0644); err != nil {
return errors.New("Unable to update local branch file. Fix by running: echo '" + target + "' > " + utils.Paths.CurrBranchPath)
}
return nil
}
Expand Down
16 changes: 8 additions & 8 deletions internal/db/branch/switch_/switch__test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func TestSwitchCommand(t *testing.T) {
require.NoError(t, utils.WriteConfig(fsys, false))
// Setup target branch
branch := "target"
branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), branch)
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), branch)
require.NoError(t, fsys.Mkdir(branchPath, 0755))
require.NoError(t, afero.WriteFile(fsys, utils.CurrBranchPath, []byte("main"), 0644))
require.NoError(t, afero.WriteFile(fsys, utils.Paths.CurrBranchPath, []byte("main"), 0644))
// Setup mock docker
require.NoError(t, apitest.MockDocker(utils.Docker))
defer gock.OffAll()
Expand Down Expand Up @@ -57,15 +57,15 @@ func TestSwitchCommand(t *testing.T) {
assert.NoError(t, Run(context.Background(), branch, fsys, conn.Intercept))
// Validate output
assert.Empty(t, apitest.ListUnmatchedRequests())
contents, err := afero.ReadFile(fsys, utils.CurrBranchPath)
contents, err := afero.ReadFile(fsys, utils.Paths.CurrBranchPath)
assert.NoError(t, err)
assert.Equal(t, []byte(branch), contents)
})

t.Run("throws error on malformed config", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
require.NoError(t, afero.WriteFile(fsys, utils.ConfigPath, []byte("malformed"), 0644))
require.NoError(t, afero.WriteFile(fsys, utils.Paths.ConfigPath, []byte("malformed"), 0644))
// Run test
err := Run(context.Background(), "target", fsys)
// Check error
Expand Down Expand Up @@ -138,13 +138,13 @@ func TestSwitchCommand(t *testing.T) {
JSON(container.InspectResponse{})
// Setup target branch
branch := "main"
branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), branch)
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), branch)
require.NoError(t, fsys.Mkdir(branchPath, 0755))
// Run test
assert.NoError(t, Run(context.Background(), branch, fsys))
// Check error
assert.Empty(t, apitest.ListUnmatchedRequests())
contents, err := afero.ReadFile(fsys, utils.CurrBranchPath)
contents, err := afero.ReadFile(fsys, utils.Paths.CurrBranchPath)
assert.NoError(t, err)
assert.Equal(t, []byte(branch), contents)
})
Expand All @@ -162,7 +162,7 @@ func TestSwitchCommand(t *testing.T) {
JSON(container.InspectResponse{})
// Setup target branch
branch := "target"
branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), branch)
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), branch)
require.NoError(t, fsys.Mkdir(branchPath, 0755))
// Setup mock postgres
conn := pgtest.NewConn()
Expand All @@ -186,7 +186,7 @@ func TestSwitchCommand(t *testing.T) {
JSON(container.InspectResponse{})
// Setup target branch
branch := "main"
branchPath := filepath.Join(filepath.Dir(utils.CurrBranchPath), branch)
branchPath := filepath.Join(filepath.Dir(utils.Paths.CurrBranchPath), branch)
require.NoError(t, fsys.Mkdir(branchPath, 0755))
// Run test
err := Run(context.Background(), branch, afero.NewReadOnlyFs(fsys))
Expand Down
6 changes: 3 additions & 3 deletions internal/db/diff/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ func loadDeclaredSchemas(fsys afero.Fs) ([]string, error) {
if schemas := utils.Config.Db.Migrations.SchemaPaths; len(schemas) > 0 {
return schemas.Files(afero.NewIOFS(fsys))
}
if exists, err := afero.DirExists(fsys, utils.SchemasDir); err != nil {
if exists, err := afero.DirExists(fsys, utils.Paths.SchemasDir); err != nil {
return nil, errors.Errorf("failed to check schemas: %w", err)
} else if !exists {
return nil, nil
}
var declared []string
if err := afero.Walk(fsys, utils.SchemasDir, func(path string, info fs.FileInfo, err error) error {
if err := afero.Walk(fsys, utils.Paths.SchemasDir, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func ConnectShadowDatabase(ctx context.Context, timeout time.Duration, options .
const CREATE_TEMPLATE = "CREATE DATABASE contrib_regression TEMPLATE postgres"

func MigrateShadowDatabase(ctx context.Context, container string, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error {
migrations, err := migration.ListLocalMigrations(utils.MigrationsDir, afero.NewIOFS(fsys))
migrations, err := migration.ListLocalMigrations(utils.Paths.MigrationsDir, afero.NewIOFS(fsys))
if err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions internal/db/diff/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ func TestRun(t *testing.T) {
assert.NoError(t, err)
assert.Empty(t, apitest.ListUnmatchedRequests())
// Check diff file
files, err := afero.ReadDir(fsys, utils.MigrationsDir)
files, err := afero.ReadDir(fsys, utils.Paths.MigrationsDir)
assert.NoError(t, err)
assert.Equal(t, 1, len(files))
diffPath := filepath.Join(utils.MigrationsDir, files[0].Name())
diffPath := filepath.Join(utils.Paths.MigrationsDir, files[0].Name())
contents, err := afero.ReadFile(fsys, diffPath)
assert.NoError(t, err)
assert.Equal(t, []byte(diff), contents)
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestMigrateShadow(t *testing.T) {
utils.InitialSchemaPg14Sql = "create schema private"
// Setup in-memory fs
fsys := afero.NewMemMapFs()
path := filepath.Join(utils.MigrationsDir, "0_test.sql")
path := filepath.Join(utils.Paths.MigrationsDir, "0_test.sql")
sql := "create schema test"
require.NoError(t, afero.WriteFile(fsys, path, []byte(sql), 0644))
// Setup mock postgres
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestMigrateShadow(t *testing.T) {

t.Run("throws error on permission denied", func(t *testing.T) {
// Setup in-memory fs
fsys := &fstest.OpenErrorFs{DenyPath: utils.MigrationsDir}
fsys := &fstest.OpenErrorFs{DenyPath: utils.Paths.MigrationsDir}
// Run test
err := MigrateShadowDatabase(context.Background(), "", fsys)
// Check error
Expand Down Expand Up @@ -278,7 +278,7 @@ create schema public`)
t.Run("throws error on failure to diff target", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
path := filepath.Join(utils.MigrationsDir, "0_test.sql")
path := filepath.Join(utils.Paths.MigrationsDir, "0_test.sql")
sql := "create schema test"
require.NoError(t, afero.WriteFile(fsys, path, []byte(sql), 0644))
// Setup mock docker
Expand Down Expand Up @@ -346,10 +346,10 @@ func TestDropStatements(t *testing.T) {

func TestLoadSchemas(t *testing.T) {
expected := []string{
filepath.Join(utils.SchemasDir, "comment", "model.sql"),
filepath.Join(utils.SchemasDir, "model.sql"),
filepath.Join(utils.SchemasDir, "reaction", "dislike", "model.sql"),
filepath.Join(utils.SchemasDir, "reaction", "like", "model.sql"),
filepath.Join(utils.Paths.SchemasDir, "comment", "model.sql"),
filepath.Join(utils.Paths.SchemasDir, "model.sql"),
filepath.Join(utils.Paths.SchemasDir, "reaction", "dislike", "model.sql"),
filepath.Join(utils.Paths.SchemasDir, "reaction", "like", "model.sql"),
}
fsys := afero.NewMemMapFs()
for _, fp := range expected {
Expand Down
2 changes: 1 addition & 1 deletion internal/db/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
var (
errMissing = errors.New("No migrations found")
errInSync = errors.New("No schema changes found")
errConflict = errors.Errorf("The remote database's migration history does not match local files in %s directory.", utils.MigrationsDir)
errConflict = errors.Errorf("The remote database's migration history does not match local files in %s directory.", utils.Paths.MigrationsDir)
)

func Run(ctx context.Context, schema []string, config pgconn.Config, name string, fsys afero.Fs, options ...func(*pgx.ConnConfig)) error {
Expand Down
8 changes: 4 additions & 4 deletions internal/db/pull/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestPullSchema(t *testing.T) {
t.Run("throws error on diff failure", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
path := filepath.Join(utils.MigrationsDir, "0_test.sql")
path := filepath.Join(utils.Paths.MigrationsDir, "0_test.sql")
require.NoError(t, afero.WriteFile(fsys, path, []byte(""), 0644))
// Setup mock docker
require.NoError(t, apitest.MockDocker(utils.Docker))
Expand All @@ -110,7 +110,7 @@ func TestPullSchema(t *testing.T) {
func TestSyncRemote(t *testing.T) {
t.Run("throws error on permission denied", func(t *testing.T) {
// Setup in-memory fs
fsys := &fstest.OpenErrorFs{DenyPath: utils.MigrationsDir}
fsys := &fstest.OpenErrorFs{DenyPath: utils.Paths.MigrationsDir}
// Setup mock postgres
conn := pgtest.NewConn()
defer conn.Close(t)
Expand All @@ -126,7 +126,7 @@ func TestSyncRemote(t *testing.T) {
t.Run("throws error on mismatched length", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
path := filepath.Join(utils.MigrationsDir, "0_test.sql")
path := filepath.Join(utils.Paths.MigrationsDir, "0_test.sql")
require.NoError(t, afero.WriteFile(fsys, path, []byte(""), 0644))
// Setup mock postgres
conn := pgtest.NewConn()
Expand All @@ -143,7 +143,7 @@ func TestSyncRemote(t *testing.T) {
t.Run("throws error on mismatched migration", func(t *testing.T) {
// Setup in-memory fs
fsys := afero.NewMemMapFs()
path := filepath.Join(utils.MigrationsDir, "0_test.sql")
path := filepath.Join(utils.Paths.MigrationsDir, "0_test.sql")
require.NoError(t, afero.WriteFile(fsys, path, []byte(""), 0644))
// Setup mock postgres
conn := pgtest.NewConn()
Expand Down
4 changes: 2 additions & 2 deletions internal/db/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ func Run(ctx context.Context, dryRun, ignoreVersionMismatch bool, includeRoles,
}
var globals []string
if includeRoles {
if exists, err := afero.Exists(fsys, utils.CustomRolesPath); err != nil {
if exists, err := afero.Exists(fsys, utils.Paths.CustomRolesPath); err != nil {
return errors.Errorf("failed to find custom roles: %w", err)
} else if exists {
globals = append(globals, utils.CustomRolesPath)
globals = append(globals, utils.Paths.CustomRolesPath)
}
}
if len(pending) == 0 && len(seeds) == 0 && len(globals) == 0 {
Expand Down
Loading
Loading