mirror of
https://github.com/coder/coder.git
synced 2026-06-06 06:28:20 +00:00
6dae48a1a8
* feat(cli): add test for delete This adds a new test for the `delete` command to ensure it works as expected when provided the correct args. * fix(cli): use ExecuteC() to match Cobra This modifies the `cli.Root().Execute()` to `cli.Root).ExecuteC()` to match the default behavior of Cobra. We do this so errors will always print the "run --help" line. * feat(cli): add WithoutParameters test for delete This adds a new test to the `delete_test.go` suite to ensure the correct behavior occurs when `delete` is called without an argument. * fixup! feat(cli): add WithoutParameters test for delete * refactor(cli): show --help error message on main This adds an error message which shows when there is an error with any commands called to improve the UX. * fixup! refactor(cli): show --help error message on main * refactor(cli): handle err with FormatCobraError This adds a new helper function called `FormatCobraError` to `root.go` so that we can colorize and add "--help" message to cobra command errors like calling `delete`. * refactor(cli): add root_test.go, move delete test
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package cli_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/cli/clitest"
|
|
"github.com/coder/coder/coderd/coderdtest"
|
|
"github.com/coder/coder/pty/ptytest"
|
|
)
|
|
|
|
func TestDelete(t *testing.T) {
|
|
t.Run("WithParameter", func(t *testing.T) {
|
|
t.Parallel()
|
|
client := coderdtest.New(t, nil)
|
|
user := coderdtest.CreateFirstUser(t, client)
|
|
coderdtest.NewProvisionerDaemon(t, client)
|
|
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
|
|
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
|
|
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
|
|
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
|
|
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)
|
|
cmd, root := clitest.New(t, "delete", workspace.Name)
|
|
clitest.SetupConfig(t, client, root)
|
|
doneChan := make(chan struct{})
|
|
pty := ptytest.New(t)
|
|
cmd.SetIn(pty.Input())
|
|
cmd.SetOut(pty.Output())
|
|
go func() {
|
|
defer close(doneChan)
|
|
err := cmd.Execute()
|
|
require.NoError(t, err)
|
|
}()
|
|
pty.ExpectMatch("Cleaning Up")
|
|
<-doneChan
|
|
})
|
|
}
|