Skip to content

Commit

Permalink
Fix dbt delete without project path (#1678)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremybeard authored and kushalmalani committed Jul 18, 2024
1 parent e6a29fc commit d89d5f6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
16 changes: 11 additions & 5 deletions cmd/cloud/dbt.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,23 @@ func deleteDbt(cmd *cobra.Command, args []string) error {

// if the mount path is not provided, derive it from the dbt project name
if mountPath == "" {
// if the dbt project path is not provided, use the current directory
if dbtProjectPath == "" {
dbtProjectPath = config.WorkingPath
}

// check that there is a valid dbt project at the dbt project path
err := validateDbtProjectExists(dbtProjectPath)
if err != nil {
return err
}

// extract the dbt project's name
dbtProjectName, err := extractDbtProjectName(dbtProjectPath)
if err != nil {
return fmt.Errorf("dbt project name not found in %s: %w", dbtProjectPath, err)
}

// if the dbt project path is not provided, use the current directory
if dbtProjectPath == "" {
dbtProjectPath = config.WorkingPath
}

mountPath = dbtDefaultMountPathPrefix + dbtProjectName
}

Expand Down
40 changes: 25 additions & 15 deletions cmd/cloud/dbt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ func (s *DbtSuite) SetupTest() {
}

func (s *DbtSuite) TearDownTest() {
s.mockPlatformCoreClient.AssertExpectations(s.T())
s.mockCoreClient.AssertExpectations(s.T())

platformCoreClient = s.origPlatformCoreClient
astroCoreClient = s.origCoreClient
DeployBundle = s.origDeployBundle
Expand All @@ -68,8 +71,6 @@ func (s *DbtSuite) TestDbtDeploy_PickDeployment() {
defer testUtil.MockUserInput(s.T(), "1")()
err := testExecCmd(newDbtDeployCmd())
assert.NoError(s.T(), err)

s.mockPlatformCoreClient.AssertExpectations(s.T())
}

func (s *DbtSuite) TestDbtDeploy_ProvidedDeploymentId() {
Expand All @@ -82,8 +83,6 @@ func (s *DbtSuite) TestDbtDeploy_ProvidedDeploymentId() {

err := testExecCmd(newDbtDeployCmd(), "test-deployment-id")
assert.NoError(s.T(), err)

s.mockPlatformCoreClient.AssertExpectations(s.T())
}

func (s *DbtSuite) TestDbtDeploy_CustomProjectPath() {
Expand All @@ -104,8 +103,6 @@ func (s *DbtSuite) TestDbtDeploy_CustomProjectPath() {
defer testUtil.MockUserInput(s.T(), "1")()
err = testExecCmd(newDbtDeployCmd(), "test-deployment-id", "--project-path", projectPath)
assert.NoError(s.T(), err)

s.mockPlatformCoreClient.AssertExpectations(s.T())
}

func (s *DbtSuite) TestDbtDeploy_CustomMountPath() {
Expand All @@ -122,8 +119,6 @@ func (s *DbtSuite) TestDbtDeploy_CustomMountPath() {
defer testUtil.MockUserInput(s.T(), "1")()
err := testExecCmd(newDbtDeployCmd(), "test-deployment-id", "--mount-path", dbtDefaultMountPathPrefix+"test_dbt_project")
assert.NoError(s.T(), err)

s.mockPlatformCoreClient.AssertExpectations(s.T())
}

func (s *DbtSuite) TestDbtDeploy_WithinAstroProject() {
Expand All @@ -150,8 +145,6 @@ func (s *DbtSuite) TestDbtDelete_PickDeployment() {
defer testUtil.MockUserInput(s.T(), "1")()
err := testExecCmd(newDbtDeleteCmd())
assert.NoError(s.T(), err)

s.mockPlatformCoreClient.AssertExpectations(s.T())
}

func (s *DbtSuite) TestDbtDelete_ProvidedDeploymentId() {
Expand All @@ -164,8 +157,6 @@ func (s *DbtSuite) TestDbtDelete_ProvidedDeploymentId() {

err := testExecCmd(newDbtDeleteCmd(), "test-deployment-id")
assert.NoError(s.T(), err)

s.mockPlatformCoreClient.AssertExpectations(s.T())
}

func (s *DbtSuite) TestDbtDelete_CustomProjectPath() {
Expand All @@ -186,8 +177,29 @@ func (s *DbtSuite) TestDbtDelete_CustomProjectPath() {
defer testUtil.MockUserInput(s.T(), "1")()
err = testExecCmd(newDbtDeleteCmd(), "test-deployment-id", "--project-path", projectPath)
assert.NoError(s.T(), err)
}

s.mockPlatformCoreClient.AssertExpectations(s.T())
func (s *DbtSuite) TestDbtDelete_NoMountPathOrProjectPath() {
s.createDbtProjectFile("dbt_project.yml")
defer os.Remove("dbt_project.yml")

DeleteBundle = func(deleteInput *cloud.DeleteBundleInput) error {
if deleteInput.MountPath != dbtDefaultMountPathPrefix+"test_dbt_project" {
return assert.AnError
}
return nil
}

defer testUtil.MockUserInput(s.T(), "1")()
err := testExecCmd(newDbtDeleteCmd(), "test-deployment-id")
assert.NoError(s.T(), err)
}

func (s *DbtSuite) TestDbtDelete_NoMountPathOrProjectPath_MissingProject() {
defer testUtil.MockUserInput(s.T(), "1")()
err := testExecCmd(newDbtDeleteCmd(), "test-deployment-id")
assert.Error(s.T(), err)
assert.Contains(s.T(), err.Error(), "dbt project file not found")
}

func (s *DbtSuite) TestDbtDelete_CustomMountPath() {
Expand All @@ -204,8 +216,6 @@ func (s *DbtSuite) TestDbtDelete_CustomMountPath() {
defer testUtil.MockUserInput(s.T(), "1")()
err := testExecCmd(newDbtDeleteCmd(), "test-deployment-id", "--mount-path", dbtDefaultMountPathPrefix+"test_dbt_project")
assert.NoError(s.T(), err)

s.mockPlatformCoreClient.AssertExpectations(s.T())
}

func testExecCmd(cmd *cobra.Command, args ...string) error {
Expand Down

0 comments on commit d89d5f6

Please sign in to comment.