Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APPS-9765 Add command to restart apps #1608

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add test
  • Loading branch information
blesswinsamuel committed Nov 19, 2024
commit 9e180d49d7d8bc0b3785b28e74a9d3b9f53cf0e5
105 changes: 105 additions & 0 deletions commands/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func TestAppsCommand(t *testing.T) {
"list-regions",
"logs",
"propose",
"restart",
"spec",
"tier",
"list-alerts",
Expand Down Expand Up @@ -344,6 +345,110 @@ func TestRunAppsCreateDeploymentWithWait(t *testing.T) {
})
}

func TestRunAppsRestart(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
appID := uuid.New().String()
deployment := &godo.Deployment{
ID: uuid.New().String(),
Spec: &testAppSpec,
Services: []*godo.DeploymentService{{
Name: "service",
SourceCommitHash: "commit",
}},
Cause: "Manual",
Phase: godo.DeploymentPhase_PendingDeploy,
Progress: &godo.DeploymentProgress{
PendingSteps: 1,
RunningSteps: 0,
SuccessSteps: 0,
ErrorSteps: 0,
TotalSteps: 1,

Steps: []*godo.DeploymentProgressStep{{
Name: "name",
Status: "pending",
StartedAt: time.Now(),
}},
},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}

tm.apps.EXPECT().Restart(appID, []string{"component1", "component2"}).Times(1).Return(deployment, nil)

config.Args = append(config.Args, appID)
config.Doit.Set(config.NS, doctl.ArgAppComponents, []string{"component1", "component2"})

err := RunAppsRestart(config)
require.NoError(t, err)
})
}

func TestRunAppsRestartWithWait(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
appID := uuid.New().String()
deployment := &godo.Deployment{
ID: uuid.New().String(),
Spec: &testAppSpec,
Services: []*godo.DeploymentService{{
Name: "service",
SourceCommitHash: "commit",
}},
Cause: "Manual",
Phase: godo.DeploymentPhase_PendingDeploy,
Progress: &godo.DeploymentProgress{
PendingSteps: 1,
RunningSteps: 0,
SuccessSteps: 0,
ErrorSteps: 0,
TotalSteps: 1,

Steps: []*godo.DeploymentProgressStep{{
Name: "name",
Status: "pending",
StartedAt: time.Now(),
}},
},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}
activeDeployment := &godo.Deployment{
ID: uuid.New().String(),
Spec: &testAppSpec,
Services: []*godo.DeploymentService{{
Name: "service",
SourceCommitHash: "commit",
}},
Cause: "Manual",
Phase: godo.DeploymentPhase_Active,
Progress: &godo.DeploymentProgress{
PendingSteps: 1,
RunningSteps: 0,
SuccessSteps: 1,
ErrorSteps: 0,
TotalSteps: 1,

Steps: []*godo.DeploymentProgressStep{{
Name: "name",
Status: "pending",
StartedAt: time.Now(),
}},
},
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
}

tm.apps.EXPECT().Restart(appID, nil).Times(1).Return(deployment, nil)
tm.apps.EXPECT().GetDeployment(appID, deployment.ID).Times(2).Return(activeDeployment, nil)

config.Args = append(config.Args, appID)
config.Doit.Set(config.NS, doctl.ArgCommandWait, true)

err := RunAppsRestart(config)
require.NoError(t, err)
})
}

func TestRunAppsGetDeployment(t *testing.T) {
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
appID := uuid.New().String()
Expand Down
15 changes: 15 additions & 0 deletions do/mocks/AppsService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.