-
Notifications
You must be signed in to change notification settings - Fork 17
Add database start and database stop commands #144
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package database | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/UpCloudLtd/upcloud-cli/internal/commands" | ||
| "github.com/UpCloudLtd/upcloud-cli/internal/completion" | ||
| "github.com/UpCloudLtd/upcloud-cli/internal/output" | ||
| "github.com/UpCloudLtd/upcloud-cli/internal/resolver" | ||
|
|
||
| "github.com/UpCloudLtd/upcloud-go-api/v4/upcloud/request" | ||
| ) | ||
|
|
||
| // StartCommand creates the "database start" command | ||
| func StartCommand() commands.Command { | ||
| return &startCommand{ | ||
| BaseCommand: commands.New( | ||
| "start", | ||
| "Start on a managed database", | ||
| "upctl database start b0952286-1193-4a81-a1af-62efc014ae4b", | ||
| "upctl database start b0952286-1193-4a81-a1af-62efc014ae4b 666bcd3c-5c63-428d-a4fd-07c27469a5a6", | ||
| "upctl database start pg-1x1xcpu-2gb-25gb-pl-waw1", | ||
| ), | ||
| } | ||
| } | ||
|
|
||
| type startCommand struct { | ||
| *commands.BaseCommand | ||
| completion.Database | ||
| resolver.CachingDatabase | ||
| } | ||
|
|
||
| // Execute implements commands.MultipleArgumentCommand | ||
| func (s *startCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) { | ||
| svc := exec.All() | ||
| msg := fmt.Sprintf("Starting database %v", uuid) | ||
| logline := exec.NewLogEntry(msg) | ||
|
|
||
| logline.StartedNow() | ||
| logline.SetMessage(fmt.Sprintf("%s: sending request", msg)) | ||
|
|
||
| res, err := svc.StartManagedDatabase(&request.StartManagedDatabaseRequest{ | ||
| UUID: uuid, | ||
| }) | ||
| if err != nil { | ||
| return commands.HandleError(logline, fmt.Sprintf("%s: failed", msg), err) | ||
| } | ||
|
|
||
| logline.SetMessage(fmt.Sprintf("%s: done", msg)) | ||
| logline.MarkDone() | ||
|
|
||
| return output.OnlyMarshaled{Value: res}, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package database | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/UpCloudLtd/upcloud-cli/internal/commands" | ||
| "github.com/UpCloudLtd/upcloud-cli/internal/config" | ||
| smock "github.com/UpCloudLtd/upcloud-cli/internal/mock" | ||
| "github.com/UpCloudLtd/upcloud-cli/internal/mockexecute" | ||
| internal "github.com/UpCloudLtd/upcloud-cli/internal/service" | ||
|
|
||
| "github.com/UpCloudLtd/upcloud-go-api/v4/upcloud" | ||
| "github.com/UpCloudLtd/upcloud-go-api/v4/upcloud/request" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestStartCommand(t *testing.T) { | ||
| targetMethod := "StartManagedDatabase" | ||
|
|
||
| var db = upcloud.ManagedDatabase{ | ||
| State: upcloud.ManagedDatabaseStateRunning, | ||
| Title: "database-title", | ||
| UUID: "1fdfda29-ead1-4855-b71f-1e33eb2ca9de", | ||
| } | ||
|
|
||
| req := request.StartManagedDatabaseRequest{ | ||
| UUID: db.UUID, | ||
| } | ||
|
|
||
| conf := config.New() | ||
| testCmd := StartCommand() | ||
| mService := new(smock.Service) | ||
|
|
||
| conf.Service = internal.Wrapper{Service: mService} | ||
| mService.On(targetMethod, &req).Return(&db, nil) | ||
|
|
||
| command := commands.BuildCommand(testCmd, nil, conf) | ||
|
|
||
| command.Cobra().SetArgs([]string{db.UUID}) | ||
| _, err := mockexecute.MockExecute(command, mService, conf) | ||
|
|
||
| assert.NoError(t, err) | ||
| mService.AssertNumberOfCalls(t, targetMethod, 1) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package database | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/UpCloudLtd/upcloud-cli/internal/commands" | ||
| "github.com/UpCloudLtd/upcloud-cli/internal/completion" | ||
| "github.com/UpCloudLtd/upcloud-cli/internal/output" | ||
| "github.com/UpCloudLtd/upcloud-cli/internal/resolver" | ||
|
|
||
| "github.com/UpCloudLtd/upcloud-go-api/v4/upcloud/request" | ||
| ) | ||
|
|
||
| // StopCommand creates the "database stop" command | ||
| func StopCommand() commands.Command { | ||
| return &stopCommand{ | ||
| BaseCommand: commands.New( | ||
| "stop", | ||
| "Stop a managed database", | ||
| "upctl database stop b0952286-1193-4a81-a1af-62efc014ae4b", | ||
| "upctl database stop b0952286-1193-4a81-a1af-62efc014ae4b 666bcd3c-5c63-428d-a4fd-07c27469a5a6", | ||
| "upctl database stop pg-1x1xcpu-2gb-25gb-pl-waw1", | ||
| ), | ||
| } | ||
| } | ||
|
|
||
| type stopCommand struct { | ||
| *commands.BaseCommand | ||
| completion.Database | ||
| resolver.CachingDatabase | ||
| } | ||
|
|
||
| // InitCommand implements Command.InitCommand | ||
| func (s *stopCommand) InitCommand() { | ||
| s.Cobra().Aliases = []string{"shutdown"} | ||
| } | ||
|
|
||
| // Execute implements commands.MultipleArgumentCommand | ||
| func (s *stopCommand) Execute(exec commands.Executor, uuid string) (output.Output, error) { | ||
| svc := exec.All() | ||
| msg := fmt.Sprintf("Stopping database %v", uuid) | ||
| logline := exec.NewLogEntry(msg) | ||
|
|
||
| logline.StartedNow() | ||
| logline.SetMessage(fmt.Sprintf("%s: sending request", msg)) | ||
|
|
||
| res, err := svc.ShutdownManagedDatabase(&request.ShutdownManagedDatabaseRequest{ | ||
| UUID: uuid, | ||
| }) | ||
| if err != nil { | ||
| return commands.HandleError(logline, fmt.Sprintf("%s: failed", msg), err) | ||
| } | ||
|
|
||
| logline.SetMessage(fmt.Sprintf("%s: done", msg)) | ||
| logline.MarkDone() | ||
|
|
||
| return output.OnlyMarshaled{Value: res}, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package database | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/UpCloudLtd/upcloud-cli/internal/commands" | ||
| "github.com/UpCloudLtd/upcloud-cli/internal/config" | ||
| smock "github.com/UpCloudLtd/upcloud-cli/internal/mock" | ||
| "github.com/UpCloudLtd/upcloud-cli/internal/mockexecute" | ||
| internal "github.com/UpCloudLtd/upcloud-cli/internal/service" | ||
|
|
||
| "github.com/UpCloudLtd/upcloud-go-api/v4/upcloud" | ||
| "github.com/UpCloudLtd/upcloud-go-api/v4/upcloud/request" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestStopCommand(t *testing.T) { | ||
| targetMethod := "ShutdownManagedDatabase" | ||
|
|
||
| var db = upcloud.ManagedDatabase{ | ||
| State: upcloud.ManagedDatabaseStateRunning, | ||
| Title: "database-title", | ||
| UUID: "1fdfda29-ead1-4855-b71f-1e33eb2ca9de", | ||
| } | ||
|
|
||
| req := request.ShutdownManagedDatabaseRequest{ | ||
| UUID: db.UUID, | ||
| } | ||
|
|
||
| conf := config.New() | ||
| testCmd := StopCommand() | ||
| mService := new(smock.Service) | ||
|
|
||
| conf.Service = internal.Wrapper{Service: mService} | ||
| mService.On(targetMethod, &req).Return(&db, nil) | ||
|
|
||
| command := commands.BuildCommand(testCmd, nil, conf) | ||
|
|
||
| command.Cobra().SetArgs([]string{db.UUID}) | ||
| _, err := mockexecute.MockExecute(command, mService, conf) | ||
|
|
||
| assert.NoError(t, err) | ||
| mService.AssertNumberOfCalls(t, targetMethod, 1) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
personally I would keep each command as a separate item on the list, for me that easier to quickly parse with eyes. Not a blocker or anything ofc.