Skip to content

refactor: Rename 'expect' package to 'console' #297

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

Merged
merged 4 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rename expect -> console
  • Loading branch information
bryphe-coder committed Feb 15, 2022
commit a5c704246fbd71a95daa7f5ce1596efebe44c5cf
11 changes: 6 additions & 5 deletions cli/clitest/clitest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package clitest_test
import (
"testing"

"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/expect"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/console"
)

func TestMain(m *testing.M) {
Expand All @@ -20,11 +21,11 @@ func TestCli(t *testing.T) {
client := coderdtest.New(t)
cmd, config := clitest.New(t)
clitest.SetupConfig(t, client, config)
console := expect.NewTestConsole(t, cmd)
testConsole := console.New(t, cmd)
go func() {
err := cmd.Execute()
require.NoError(t, err)
}()
_, err := console.ExpectString("coder")
_, err := testConsole.ExpectString("coder")
require.NoError(t, err)
}
4 changes: 2 additions & 2 deletions cli/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"testing"

"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/expect"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/console"
"github.com/stretchr/testify/require"
)

Expand All @@ -26,7 +26,7 @@ func TestLogin(t *testing.T) {
// accurately detect Windows ptys when they are not attached to a process:
// https://github.com/mattn/go-isatty/issues/59
root, _ := clitest.New(t, "login", client.URL.String(), "--force-tty")
console := expect.NewTestConsole(t, root)
console := console.New(t, root)
go func() {
err := root.Execute()
require.NoError(t, err)
Expand Down
6 changes: 3 additions & 3 deletions cli/projectcreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/console"
"github.com/coder/coder/database"
"github.com/coder/coder/expect"
"github.com/coder/coder/provisioner/echo"
"github.com/coder/coder/provisionersdk/proto"
)
Expand All @@ -26,7 +26,7 @@ func TestProjectCreate(t *testing.T) {
cmd, root := clitest.New(t, "projects", "create", "--directory", source, "--provisioner", string(database.ProvisionerTypeEcho))
clitest.SetupConfig(t, client, root)
_ = coderdtest.NewProvisionerDaemon(t, client)
console := expect.NewTestConsole(t, cmd)
console := console.New(t, cmd)
closeChan := make(chan struct{})
go func() {
err := cmd.Execute()
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestProjectCreate(t *testing.T) {
cmd, root := clitest.New(t, "projects", "create", "--directory", source, "--provisioner", string(database.ProvisionerTypeEcho))
clitest.SetupConfig(t, client, root)
coderdtest.NewProvisionerDaemon(t, client)
console := expect.NewTestConsole(t, cmd)
console := console.New(t, cmd)
closeChan := make(chan struct{})
go func() {
err := cmd.Execute()
Expand Down
4 changes: 2 additions & 2 deletions cli/workspacecreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/expect"
"github.com/coder/coder/console"
"github.com/coder/coder/provisioner/echo"
"github.com/coder/coder/provisionersdk/proto"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -36,7 +36,7 @@ func TestWorkspaceCreate(t *testing.T) {
cmd, root := clitest.New(t, "workspaces", "create", project.Name)
clitest.SetupConfig(t, client, root)

console := expect.NewTestConsole(t, cmd)
console := console.New(t, cmd)
closeChan := make(chan struct{})
go func() {
err := cmd.Execute()
Expand Down
4 changes: 2 additions & 2 deletions console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package expect
package console

import (
"bufio"
Expand All @@ -23,7 +23,7 @@ import (
"os"
"unicode/utf8"

"github.com/coder/coder/expect/pty"
"github.com/coder/coder/console/pty"
)

// Console is an interface to automate input and output for interactive
Expand Down
2 changes: 1 addition & 1 deletion console/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
// applications. It is unlike expect in that it does not spawn or manage
// process lifecycle. This package only focuses on expecting output and sending
// input through it's psuedoterminal.
package expect
package console
2 changes: 1 addition & 1 deletion console/expect.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package expect
package console

import (
"bufio"
Expand Down
2 changes: 1 addition & 1 deletion console/expect_opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package expect
package console

import (
"bytes"
Expand Down
4 changes: 2 additions & 2 deletions console/expect_opt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package expect_test
package console_test

import (
"bytes"
"testing"

"github.com/stretchr/testify/require"

. "github.com/coder/coder/expect"
. "github.com/coder/coder/console"
)

func TestExpectOptString(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions console/expect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package expect_test
package console_test

import (
"bufio"
Expand All @@ -26,7 +26,7 @@ import (

"golang.org/x/xerrors"

. "github.com/coder/coder/expect"
. "github.com/coder/coder/console"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion console/pty/pty_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"golang.org/x/sys/windows"

"github.com/coder/coder/expect/conpty"
"github.com/coder/coder/console/conpty"
)

func newPty() (Pty, error) {
Expand Down
6 changes: 3 additions & 3 deletions console/test_console.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package expect
package console

import (
"bufio"
Expand All @@ -16,9 +16,9 @@ var (
stripAnsi = regexp.MustCompile("[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))")
)

// NewTestConsole creates a new TTY bound to the command provided.
// New creates a new TTY bound to the command provided.
// All ANSI escape codes are stripped to provide clean output.
func NewTestConsole(t *testing.T, cmd *cobra.Command) *Console {
func New(t *testing.T, cmd *cobra.Command) *Console {
reader, writer := io.Pipe()
scanner := bufio.NewScanner(reader)
t.Cleanup(func() {
Expand Down