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
546 changes: 546 additions & 0 deletions api/v1alpha1/blueprint_types_test.go

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
)

var installCmd = &cobra.Command{
Use: "install",
Short: "Install the blueprint's cluster-level services",
Use: "install",
Short: "Install the blueprint's cluster-level services",
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
controller := cmd.Context().Value(controllerKey).(ctrl.Controller)

Expand Down Expand Up @@ -59,10 +60,18 @@ var installCmd = &cobra.Command{
return fmt.Errorf("Error installing blueprint: %w", err)
}

// If wait flag is set, wait for kustomizations to be ready
if waitFlag {
if err := blueprintHandler.WaitForKustomizations(); err != nil {
return fmt.Errorf("failed waiting for kustomizations: %w", err)
}
}

return nil
},
}

func init() {
installCmd.Flags().BoolVar(&waitFlag, "wait", false, "Wait for kustomization resources to be ready")
rootCmd.AddCommand(installCmd)
}
32 changes: 32 additions & 0 deletions cmd/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,36 @@ func TestInstallCmd(t *testing.T) {
t.Errorf("Expected error %q, got %q", expectedError, err.Error())
}
})

t.Run("WaitFlag_CallsWaitForKustomizations", func(t *testing.T) {
// Given a set of mocks with proper configuration
mocks := setupInstallMocks(t, nil)

// Set waitFlag = true
waitFlag = true
defer func() { waitFlag = false }()

// Set up a flag to check if WaitForKustomizations is called
called := false
mocks.BlueprintHandler.WaitForKustomizationsFunc = func() error {
called = true
return nil
}

// Set up command arguments
rootCmd.SetArgs([]string{"install"})

// When executing the command
err := Execute(mocks.Controller)

// Then no error should occur
if err != nil {
t.Errorf("Expected success, got error: %v", err)
}

// And WaitForKustomizations should have been called
if !called {
t.Error("Expected WaitForKustomizations to be called, but it was not")
}
})
}
8 changes: 8 additions & 0 deletions cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

var (
installFlag bool // Declare the install flag
waitFlag bool // Declare the wait flag
)

var upCmd = &cobra.Command{
Expand Down Expand Up @@ -143,6 +144,12 @@ var upCmd = &cobra.Command{
if err := blueprintHandler.Install(); err != nil {
return fmt.Errorf("Error installing blueprint: %w", err)
}
// If wait flag is set, poll for kustomization readiness
if waitFlag {
if err := blueprintHandler.WaitForKustomizations(); err != nil {
return fmt.Errorf("Error waiting for kustomizations: %w", err)
}
}
}

// Indicate successful setup of the Windsor environment.
Expand All @@ -154,5 +161,6 @@ var upCmd = &cobra.Command{

func init() {
upCmd.Flags().BoolVar(&installFlag, "install", false, "Install the blueprint after setting up the environment")
upCmd.Flags().BoolVar(&waitFlag, "wait", false, "Wait for kustomization resources to be ready")
rootCmd.AddCommand(upCmd)
}
25 changes: 25 additions & 0 deletions cmd/up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,29 @@ func TestUpCmd(t *testing.T) {
t.Errorf("Expected 'No blueprint handler found', got '%v'", err)
}
})

t.Run("WaitFlag_CallsWaitForKustomizations", func(t *testing.T) {
mocks := setupUpMocks(t)
installFlag = true
waitFlag = true
defer func() { installFlag = false; waitFlag = false }()

called := false
mocks.BlueprintHandler.WaitForKustomizationsFunc = func() error {
called = true
return nil
}
mocks.BlueprintHandler.InstallFunc = func() error {
return nil
}

rootCmd.SetArgs([]string{"up", "--install", "--wait"})
err := Execute(mocks.Controller)
if err != nil {
t.Errorf("Expected no error, got %v", err)
}
if !called {
t.Error("Expected WaitForKustomizations to be called, but it was not")
}
})
}
Loading
Loading