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

Add prep and storage rename CLI #309

Merged
merged 5 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/dashboard/src/client/** linguist-generated=true
/client/** linguist-generated=true
/docs/swagger/** linguist-generated=true
/docs/en/cli-reference linguist-generated=true
/docs/en/web-api-reference linguist-generated=true
21 changes: 20 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ Singularity, including all related modules, follows the
- [Issues and tracking](#issues-and-tracking)
- [Good First Issues](#good-first-issues)
- [Additional Developer Notes](#additional-developer-notes)
- [Add a new CLI command](#add-a-new-cli-command)
- [Testing](#testing)
- [Code Style](#code-style)
- [Code Generation](#code-generation)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Expand Down Expand Up @@ -104,6 +107,22 @@ To pick up an issue:

## Additional Developer Notes

### Add a new CLI command
- Create a handler implementation under `handler/*` directory
- Make proper godoc comments for the implementation
- Add the handler function to the interface under `handler/*/interface.go`
- Update the MockHandler under `handler/*/interface.go`
- Create unit tests for this handler implementation
- Create a function to document the swagger API `func _(){}`
- Create corresponding API route handler in `api/api.go`
- Create a CLI command under `cmd/*` directory
- Update `cmd/app.go` to register the new command
- Add the CLI command unit test in one of `cmd/*_test.go`
- Optionally add CLI command integration tests in `cmd/functional_test.go`
- Run `make generate` or `go generate ./...`
- Add the swagger API unit test in `api/api_test.go`
- Optionally add swagger API integration tests in `cmd/api_test.go`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hannahhoward @elijaharita
See if above makes sense to you

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it makes sense!


### Testing

- All new code should be accompanied by unit tests. Prefer focussed unit tests to integration tests for thorough validation of behaviour. Existing code is not necessarily a good model, here.
Expand All @@ -113,4 +132,4 @@ To pick up an issue:
- Make sure your code is formatted and pass `make lint` before submitting a PR.

### Code Generation
- Make sure all code generation is up to date before submitting a PR. To generate the code, run `make generate`.
- Make sure all code generations are up-to-date before submitting a PR. To generate the code, run `make generate`.
2 changes: 2 additions & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,14 @@ func (s Server) setupRoutes(e *echo.Echo) {
e.GET("/api/storage", s.toEchoHandler(s.storageHandler.ListStoragesHandler))
e.DELETE("/api/storage/:name", s.toEchoHandler(s.storageHandler.RemoveHandler))
e.PATCH("/api/storage/:name", s.toEchoHandler(s.storageHandler.UpdateStorageHandler))
e.PATCH("/api/storage/:name/rename", s.toEchoHandler(s.storageHandler.RenameStorageHandler))

// Preparation
e.POST("/api/preparation", s.toEchoHandler(s.dataprepHandler.CreatePreparationHandler))
e.GET("/api/preparation", s.toEchoHandler(s.dataprepHandler.ListHandler))
e.GET("/api/preparation/:id", s.toEchoHandler(s.jobHandler.GetStatusHandler))
e.GET("/api/preparation/:id/schedules", s.toEchoHandler(s.dataprepHandler.ListSchedulesHandler))
e.PATCH("/api/preparation/:name/rename", s.toEchoHandler(s.dataprepHandler.RenamePreparationHandler))

// Job management
e.POST("/api/preparation/:id/source/:name/start-daggen", s.toEchoHandler(s.jobHandler.StartDagGenHandler))
Expand Down
36 changes: 23 additions & 13 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/data-preservation-programs/singularity/service"
"github.com/data-preservation-programs/singularity/util"
"github.com/data-preservation-programs/singularity/util/testutil"
"github.com/gotidy/ptr"
"github.com/ipfs/go-log/v2"
"github.com/parnurzeal/gorequest"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -70,6 +71,8 @@ func setupMockDataPrep() dataprep.Handler {
Return(&model.Car{}, nil)
m.On("AddSourceStorageHandler", mock.Anything, mock.Anything, "id", "name").
Return(&model.Preparation{}, nil)
m.On("RenamePreparationHandler", mock.Anything, mock.Anything, "old", mock.Anything).
Return(&model.Preparation{}, nil)
return m
}

Expand Down Expand Up @@ -145,6 +148,8 @@ func setupMockStorage() storage.Handler {
Return(nil)
m.On("UpdateStorageHandler", mock.Anything, mock.Anything, "name", mock.Anything).
Return(&model.Storage{}, nil)
m.On("RenameStorageHandler", mock.Anything, mock.Anything, "old", mock.Anything).
Return(&model.Storage{}, nil)
return m
}

Expand Down Expand Up @@ -284,19 +289,12 @@ func TestAllAPIs(t *testing.T) {
})

t.Run("storage", func(t *testing.T) {
t.Run("CreateStorage", func(t *testing.T) {
resp, err := client.Storage.CreateStorage(&storage2.CreateStorageParams{
Body: &models.StorageCreateRequest{},
StorageType: "type",
Context: ctx,
})
require.NoError(t, err)
require.True(t, resp.IsSuccess())
require.NotNil(t, resp.Payload)
})
t.Run("CreateLocalStorage", func(t *testing.T) {
resp, err := client.Storage.CreateLocalStorage(&storage2.CreateLocalStorageParams{
Request: &models.StorageCreateLocalStorageRequest{},
t.Run("RenameStorage", func(t *testing.T) {
resp, err := client.Storage.RenameStorage(&storage2.RenameStorageParams{
Name: "old",
Request: &models.StorageRenameRequest{
Name: ptr.Of("new"),
},
Context: ctx,
})
require.NoError(t, err)
Expand Down Expand Up @@ -491,6 +489,18 @@ func TestAllAPIs(t *testing.T) {
})

t.Run("preparation", func(t *testing.T) {
t.Run("RenamePreparation", func(t *testing.T) {
resp, err := client.Preparation.RenamePreparation(&preparation.RenamePreparationParams{
Name: "old",
Request: &models.DataprepRenameRequest{
Name: ptr.Of("new"),
},
Context: ctx,
})
require.NoError(t, err)
require.True(t, resp.IsSuccess())
require.NotNil(t, resp.Payload)
})
t.Run("CreatePreparation", func(t *testing.T) {
resp, err := client.Preparation.CreatePreparation(&preparation.CreatePreparationParams{
Context: ctx,
Expand Down
40 changes: 40 additions & 0 deletions client/swagger/http/preparation/preparation_client.go

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

175 changes: 175 additions & 0 deletions client/swagger/http/preparation/rename_preparation_parameters.go

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

Loading