Skip to content

Commit

Permalink
Reorganize PersistentRunE hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
schnie committed Dec 20, 2024
1 parent 6fa7960 commit 9e815ff
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 23 deletions.
12 changes: 0 additions & 12 deletions airflow/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,18 +490,6 @@ func (s *Suite) TestDockerComposeStart() {
composeMock.AssertExpectations(s.T())
})

s.Run("project already running", func() {
composeMock := new(mocks.DockerComposeAPI)
composeMock.On("Ps", mock.Anything, mockDockerCompose.projectName, api.PsOptions{All: true}).Return([]api.ContainerSummary{{ID: "test-webserver-id", State: "running"}}, nil).Once()

mockDockerCompose.composeService = composeMock

err := mockDockerCompose.Start("", "", "", "", false, false, waitTime, nil)
s.Contains(err.Error(), "cannot start, project already running")

composeMock.AssertExpectations(s.T())
})

s.Run("compose ps failure", func() {
composeMock := new(mocks.DockerComposeAPI)
composeMock.On("Ps", mock.Anything, mockDockerCompose.projectName, api.PsOptions{All: true}).Return([]api.ContainerSummary{}, errMockDocker).Once()
Expand Down
9 changes: 6 additions & 3 deletions cmd/airflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"strings"
"time"

"github.com/astronomer/astro-cli/airflow/runtimes"

"github.com/astronomer/astro-cli/airflow"
"github.com/astronomer/astro-cli/airflow/runtimes"
airflowversions "github.com/astronomer/astro-cli/airflow_versions"
astrocore "github.com/astronomer/astro-cli/astro-client-core"
astroplatformcore "github.com/astronomer/astro-cli/astro-client-platform-core"
"github.com/astronomer/astro-cli/cloud/environment"
"github.com/astronomer/astro-cli/cmd/utils"
"github.com/astronomer/astro-cli/config"
"github.com/astronomer/astro-cli/context"
"github.com/astronomer/astro-cli/houston"
Expand Down Expand Up @@ -130,7 +130,10 @@ func newDevRootCmd(platformCoreClient astroplatformcore.CoreClient, astroCoreCli
// so we set that configuration in this persistent pre-run hook.
// A few sub-commands don't require this, so they explicitly
// clobber it with a no-op function.
PersistentPreRunE: ConfigureContainerRuntime,
PersistentPreRunE: utils.ChainRunEs(
SetupLogging,
ConfigureContainerRuntime,
),
}
cmd.AddCommand(
newAirflowInitCmd(),
Expand Down
5 changes: 0 additions & 5 deletions cmd/airflow_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"path/filepath"

"github.com/astronomer/astro-cli/airflow/runtimes"
softwareCmd "github.com/astronomer/astro-cli/cmd/software"
"github.com/astronomer/astro-cli/cmd/utils"
"github.com/astronomer/astro-cli/config"
"github.com/spf13/cobra"
Expand All @@ -29,10 +28,6 @@ func ConfigureContainerRuntime(_ *cobra.Command, _ []string) error {
if err != nil {
return err
}

if err := softwareCmd.SetUpLogs(os.Stdout, verboseLevel); err != nil {
return err
}
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewRootCmd() *cobra.Command {
Welcome to the Astro CLI, the modern command line interface for data orchestration. You can use it for Astro, Astronomer Software, or Local Development.`,
PersistentPreRunE: utils.ChainRunEs(
SetupLoggingPersistentPreRunE,
SetupLogging,
CreateRootPersistentPreRunE(astroCoreClient, platformCoreClient),
),
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/root_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (
"github.com/spf13/cobra"
)

// SetupLoggingPersistentPreRunE is a pre-run hook shared between software & cloud
// SetupLogging is a pre-run hook shared between software & cloud
// setting up log verbosity.
func SetupLoggingPersistentPreRunE(_ *cobra.Command, _ []string) error {
func SetupLogging(_ *cobra.Command, _ []string) error {
return softwareCmd.SetUpLogs(os.Stdout, verboseLevel)
}

Expand Down

0 comments on commit 9e815ff

Please sign in to comment.