-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The fix command recreate the missing folders and files to make the wo configuration works
- Loading branch information
Showing
11 changed files
with
259 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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,21 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newFixCmd(workspaceManager workspaceManager) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "fix", | ||
Short: "Fix the possible failure in the config folder", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
err := workspaceManager.Fix() | ||
if err != nil { | ||
return err | ||
} | ||
cmd.Print(regularStyle.Render("Config folder fixed")) | ||
return nil | ||
}, | ||
} | ||
} |
This file contains 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,57 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewFixCmd(t *testing.T) { | ||
type scenario struct { | ||
name string | ||
setup func(*testing.T) workspaceManager | ||
test func(*testing.T, *bytes.Buffer, *bytes.Buffer, error) | ||
} | ||
scenarios := []scenario{ | ||
{ | ||
"An error occurred when fixing the config", | ||
func(t *testing.T) workspaceManager { | ||
w := newMockWorkspaceManager(t) | ||
w.Mock.On("Fix").Return(errors.New("an error occurred")) | ||
return w | ||
}, | ||
func(t *testing.T, outBuf *bytes.Buffer, errBuf *bytes.Buffer, err error) { | ||
assert.Error(t, err) | ||
}, | ||
}, | ||
{ | ||
"Creating a workspace env successfully", | ||
func(t *testing.T) workspaceManager { | ||
w := newMockWorkspaceManager(t) | ||
w.Mock.On("Fix").Return(nil) | ||
return w | ||
}, | ||
func(t *testing.T, outBuf *bytes.Buffer, errBuf *bytes.Buffer, err error) { | ||
assert.NoError(t, err) | ||
assert.Equal(t, "Config folder fixed", outBuf.String()) | ||
}, | ||
}, | ||
} | ||
for _, s := range scenarios { | ||
t.Run(s.name, func(t *testing.T) { | ||
os.Setenv("EDITOR", "emacs") | ||
os.Setenv("SHELL", "/bin/sh") | ||
errBuf := &bytes.Buffer{} | ||
outBuf := &bytes.Buffer{} | ||
w := s.setup(t) | ||
cmd := newFixCmd(w) | ||
cmd.SetArgs([]string{}) | ||
cmd.SetErr(errBuf) | ||
cmd.SetOut(outBuf) | ||
s.test(t, outBuf, errBuf, cmd.Execute()) | ||
}) | ||
} | ||
} |
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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