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

delete design code #245

Merged
merged 1 commit into from
Oct 11, 2022
Merged

delete design code #245

merged 1 commit into from
Oct 11, 2022

Conversation

RaviKhandavilli
Copy link
Contributor

Added code to flamectl cli to Support remove command.
Added code to process remove command Http request on Api server and controller.
Added code to update DB , when a code is removed.

@codecov-commenter
Copy link

Codecov Report

Merging #245 (feea5a7) into main (cf474ab) will decrease coverage by 8.71%.
The diff coverage is 40.00%.

@@            Coverage Diff             @@
##             main     #245      +/-   ##
==========================================
- Coverage   22.41%   13.69%   -8.72%     
==========================================
  Files          35       46      +11     
  Lines        1593     2724    +1131     
==========================================
+ Hits          357      373      +16     
- Misses       1226     2339    +1113     
- Partials       10       12       +2     
Impacted Files Coverage Δ
cmd/flamectl/cmd/delete_code.go 18.18% <18.18%> (ø)
cmd/controller/app/database/mongodb/code.go 7.18% <66.66%> (ø)
cmd/controller/app/database/mongodb/watcher.go 0.00% <0.00%> (ø)
cmd/controller/app/database/mongodb/dataset.go 0.00% <0.00%> (ø)
cmd/controller/app/database/mongodb/service.go 0.00% <0.00%> (ø)
cmd/controller/app/database/mongodb/compute.go 0.00% <0.00%> (ø)
cmd/controller/app/database/mongodb/design.go 0.00% <0.00%> (ø)
cmd/controller/app/database/mongodb/helpers.go 0.00% <0.00%> (ø)
cmd/controller/app/database/mongodb/schema.go 0.00% <0.00%> (ø)
... and 2 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@myungjin myungjin left a comment

Choose a reason for hiding this comment

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

Left several comments. Please consider to revise them.

cmd/controller/app/database/mongodb/code.go Outdated Show resolved Hide resolved
cmd/controller/app/database/mongodb/code.go Outdated Show resolved Hide resolved
func TestMongoService_DeleteDesignCode(t *testing.T) {
mt := mtest.New(t, mtest.NewOptions().ClientType(mtest.Mock))
defer mt.Close()
mt.Run("success", func(mt *mtest.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this possible to add more than one code versions and delete only one of them and check if the specified version is only removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have just mocked mongo db responses here, I suggest we should do this as part of integration test.

cmd/controller/cmd/root.go Outdated Show resolved Hide resolved
cmd/flamectl/cmd/delete_code.go Show resolved Hide resolved
)

var removeCodeCmd = &cobra.Command{
Use: "code <version>",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this usage format correct? What about -d argument? Can you double-check if this format is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

-d argument was made as mandate MarkPersistentFlagRequired, so command will fail without this argument. Anyways added it in description.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for this. I was asking if someone runs flamectl remove code -h, what would be a usage output?
I was asking if the usage is correctly printed out. Should -d be part of a usage description as it is mandatory?

var removeCodeCmd = &cobra.Command{
Use: "code <version>",
Short: "Remove a code",
Long: "This command removes a code",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add more description? A code should be associated with a design. So, a code should be removed from a design. Can you make the description a bit more informative?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -72,7 +72,7 @@ func Create(params Params) error {
return nil
}

fmt.Printf("Code created successfully for design %s\n", params.DesignId)
fmt.Printf("Code created successfully for design %s, version %v\n", params.DesignId, params.CodeVer)
Copy link
Contributor

Choose a reason for hiding this comment

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

When a code is created, user doesn't need to provide CodeVer. The DB code for creating a code will determine a version (https://github.com/cisco-open/flame/pull/245/files#diff-2164dd2c9fd70fa0f3feb28786e75a81fbe9feed581c045325da3c98c5a331e0R46-R47). So, here params.CodeVer will always print 0 or some arbitrary value.

We first need to check what response body returns and make sure that a code version is in the response body.

We may have to enhance this with a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need to correct logs of flamectl in few other locations as well, we shall handle it is a part of different PR, for now removing this change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good.

func (db *MongoService) DeleteDesignCode(userId string, designId string, version string) error {
zap.S().Debugf("delete design code 1: %v, %v,%v", userId, designId, version)

if version == "" || version == latestVersion {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since it involves deletion of resource, we may want to be conservative. Perhaps would it be better to return an error if a version string is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@@ -112,3 +112,23 @@ func mustOpen(f string) *os.File {

return r
}
func Remove(params Params) error {
Copy link
Contributor

@myungjin myungjin Oct 10, 2022

Choose a reason for hiding this comment

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

Can you unit-test this code as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To write unit cases for this function we need to refactor restapi package.as this function has dependencies with functions in restapi Package.

Copy link
Contributor

@myungjin myungjin left a comment

Choose a reason for hiding this comment

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

lgtm

@myungjin myungjin merged commit 900b9ea into cisco-open:main Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants