Skip to content
Merged
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
20 changes: 0 additions & 20 deletions internal/runtime/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,23 +447,3 @@ func IsRuntimeForProject(ctx context.Context, fs afero.Fs, dirPath string, sdkCo

return false
}

// getProjectDirRelPath returns the relative path from current working directory
// to projectDirPath or an error. When an error occurs, the projectDirPath is
// returned as the relative path.
func getProjectDirRelPath(os types.Os, currentDirPath string, projectDirPath string) (string, error) {
// Get the current directory to use as the base for the project
if currentDirPath == "" {
cwd, err := os.Getwd()
if err != nil {
return projectDirPath, err
}
currentDirPath = cwd
}
// Find relative path between current directory and project directory
filePathRel, err := filepath.Rel(currentDirPath, projectDirPath)
if err != nil {
return projectDirPath, err
}
return filePathRel, nil
}
59 changes: 0 additions & 59 deletions internal/runtime/python/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,62 +775,3 @@ func Test_Python_IsRuntimeForProject(t *testing.T) {
})
}
}

func Test_Python_getProjectDirRelPath(t *testing.T) {
tests := map[string]struct {
currentDirPath string
projectDirPath string
getwdPath string
getwdError error
expectedRelPath string
expectedError error
}{
"When currentDirPath missing and Getwd returns an error": {
currentDirPath: "",
projectDirPath: "path/to/my-project",
getwdPath: "",
getwdError: fmt.Errorf("Something went wrong"),
expectedRelPath: "path/to/my-project",
expectedError: fmt.Errorf("Something went wrong"),
},
"When Rel returns an error": {
currentDirPath: "//host/some/remote/volume",
projectDirPath: "path/to/my-project",
getwdPath: "", // Not called
getwdError: nil, // Not called
expectedRelPath: "path/to/my-project",
expectedError: fmt.Errorf("Rel: can't make path/to/my-project relative to //host/some/remote/volume"),
},
"When current working directory outside the projectDirPath": {
currentDirPath: "path/to",
projectDirPath: "path/to/my-project",
getwdPath: "", // Not called
getwdError: nil, // Not called
expectedRelPath: "my-project",
expectedError: nil,
},
"When current working directory equals the projectDirPath": {
currentDirPath: "path/to/my-project",
projectDirPath: "path/to/my-project",
getwdPath: "", // Not called
getwdError: nil, // Not called
expectedRelPath: ".",
expectedError: nil,
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
// Create mocks
osMock := slackdeps.NewOsMock()
osMock.On("Getwd").Return(tc.getwdPath, tc.getwdError)
osMock.AddDefaultMocks()

// Run the test
actualRelPath, actualErr := getProjectDirRelPath(osMock, tc.currentDirPath, tc.projectDirPath)

// Assertions
require.Equal(t, tc.expectedRelPath, actualRelPath)
require.Equal(t, tc.expectedError, actualErr)
})
}
}
Loading