Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

created rit add workspace command #809

Merged
merged 1 commit into from
Dec 23, 2020
Merged

created rit add workspace command #809

merged 1 commit into from
Dec 23, 2020

Conversation

aronrichter
Copy link
Contributor

Description

As requested on #802, is necessary a command do add a new workspace.

How to verify it

You can run the command rit add workspace and after you can run rit list workspace and then you can see your workspace added

Changelog

Added a new core command rit add workspace

Copy link
Contributor

@henriquemoraeszup henriquemoraeszup left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution aron! Just a couple of points below, keep it up 💪

pkg/cmd/add_workspace.go Show resolved Hide resolved
pkg/cmd/add_workspace_test.go Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Dec 19, 2020

Codecov Report

Merging #809 (91d57e0) into master (84b0008) will decrease coverage by 0.02%.
The diff coverage is 86.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #809      +/-   ##
==========================================
- Coverage   83.80%   83.77%   -0.03%     
==========================================
  Files         110      111       +1     
  Lines        3797     3840      +43     
==========================================
+ Hits         3182     3217      +35     
- Misses        440      444       +4     
- Partials      175      179       +4     
Impacted Files Coverage Δ
pkg/cmd/add_workspace.go 85.71% <85.71%> (ø)
pkg/commands/builder.go 90.25% <100.00%> (+0.05%) ⬆️
pkg/slice/sliceutil/slice_util.go 83.33% <0.00%> (-16.67%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 84b0008...91d57e0. Read the comment docs.

@henriquemoraeszup henriquemoraeszup added the ✨ feature Suggest a new feature or enhancement to the Ritchie project label Dec 20, 2020
Comment on lines 71 to 76
workspaceName, _ := cmd.Flags().GetString(workspaceNameFlag)
workspacePath, _ := cmd.Flags().GetString(workspacePathFlag)

if len(workspaceName) == 0 && len(workspacePath) == 0 {
return formula.Workspace{}, nil, false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens if you do rit add workspace --name= --path=?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was the same thing when you don't pass any flag.
But, I understood why you'd ask, so I changed to check the number of flags passed before I decided what to do.

@henriquemoraeszup henriquemoraeszup linked an issue Dec 21, 2020 that may be closed by this pull request
1 task
wantErr string
}{
{
name: "add new workspace by prompt",
Copy link
Contributor

Choose a reason for hiding this comment

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

One detail, on a success case, you want to check if the workspace entry was actually added to ~/.rit/formula_workspaces.json so maybe you do not want to mock the workspace added

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if I wanted to check that.
My unit it's until I called the method a.workspace.Add(wspace) after that the behavior ins't responsability of this method. Because of this I mocked my test.
What do you think?!

Copy link
Contributor

Choose a reason for hiding this comment

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

I do agree with you, lately we have been trying to adopt a more functional-like approach on our tests. But your argument is good as well, if you intend to continue with the mock, then maybe it is best to test that it has been called with the right arguments to ensure a thorough test. Check out assertCalled
https://godoc.org/github.com/stretchr/testify/mock#Mock.AssertCalled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right, I can mock my test, but at least a need to guarantee I'm passing the right parameters.
Thanks for the observation! 😄

Copy link
Contributor

@henriquemoraeszup henriquemoraeszup left a comment

Choose a reason for hiding this comment

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

Just one last suggestion on the mock but I am good to go. Just not approving now because any further commit would dismiss my review

}

workspaceMock := &mocks.WorkspaceMock{}
workspaceMock.On("Add", wspace).Return(tt.addWorkspaceWithError)
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, this is even better than what I suggested 😄 will be recommending this to the team

Copy link
Contributor

@henriquemoraeszup henriquemoraeszup left a comment

Choose a reason for hiding this comment

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

👏 👏 👏 👏
giphy (12)

Copy link
Contributor

@kaduartur kaduartur left a comment

Choose a reason for hiding this comment

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

Good job 🚀

You just needed to add this command to the core command list, you can add it in the api.go file. we use this to generate our autocomplete of the core commands.


type addWorkspaceCmd struct {
workspace formula.WorkspaceAddLister
inText prompt.InputText
Copy link
Contributor

Choose a reason for hiding this comment

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

could you rename this to input to make it more readable?


func (a addWorkspaceCmd) runFormula() CommandRunnerFunc {
return func(cmd *cobra.Command, args []string) error {
if count := cmd.Flags().NFlag(); count == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

could you simplify it to cmd.Flags().NFlag() == 0?

Signed-off-by: Aron Richter <aronrichter@gmail.com>
Copy link
Contributor

@kaduartur kaduartur left a comment

Choose a reason for hiding this comment

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

LGTM 🥇

@kaduartur
Copy link
Contributor

/merge qa

@ritchie-bot
Copy link
Contributor

ritchie-bot bot commented Dec 23, 2020

🔥 Merge Conflict

@kaduartur
Copy link
Contributor

/merge qa

@ritchie-bot
Copy link
Contributor

ritchie-bot bot commented Dec 23, 2020

👌 Merged branch feature/add-workspace into qa

@kaduartur kaduartur merged commit 38d31e7 into ZupIT:master Dec 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
✔️ ready-for-review ready for review ✨ feature Suggest a new feature or enhancement to the Ritchie project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a RIT ADD WORKSPACE command
5 participants