Skip to content

Commit

Permalink
Merge pull request #69 from furiko-io/irvinlim/chore/console-package
Browse files Browse the repository at this point in the history
  • Loading branch information
irvinlim authored Apr 29, 2022
2 parents 1b52a38 + f50393a commit 50c09fd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pkg/cli/cmd/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

execution "github.com/furiko-io/furiko/apis/execution/v1alpha1"
"github.com/furiko-io/furiko/pkg/cli/cmd"
"github.com/furiko-io/furiko/pkg/cli/streams"
"github.com/furiko-io/furiko/pkg/cli/console"
runtimetesting "github.com/furiko-io/furiko/pkg/runtime/testing"
"github.com/furiko-io/furiko/pkg/utils/testutils"
)
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestRunCommand(t *testing.T) {
},
},
Stdin: runtimetesting.Input{
Procedure: func(c *streams.Console) {
Procedure: func(c *console.Console) {
c.ExpectString("Full Name")
c.SendLine("John Smith")
},
Expand All @@ -301,7 +301,7 @@ func TestRunCommand(t *testing.T) {
},
},
Stdin: runtimetesting.Input{
Procedure: func(c *streams.Console) {
Procedure: func(c *console.Console) {
c.ExpectString("Full Name")
c.SendLine("John Smith")
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/streams/console.go → pkg/cli/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package streams
package console

import (
"io"
Expand Down
10 changes: 5 additions & 5 deletions pkg/cli/streams/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ func NewStreams(streams genericclioptions.IOStreams) *Streams {
}
}

// NewConsoleStreams returns a Streams object from a Console.
func NewConsoleStreams(console *Console) *Streams {
// NewTTYStreams returns a Streams object from a TTY file.
func NewTTYStreams(tty *os.File) *Streams {
return &Streams{
In: console.Tty(),
Out: console.Tty(),
ErrOut: console.Tty(),
In: tty,
Out: tty,
ErrOut: tty,
}
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/runtime/testing/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/cli-runtime/pkg/genericclioptions"

"github.com/furiko-io/furiko/pkg/cli/cmd"
"github.com/furiko-io/furiko/pkg/cli/console"
"github.com/furiko-io/furiko/pkg/cli/streams"
"github.com/furiko-io/furiko/pkg/runtime/controllercontext/mock"
)
Expand Down Expand Up @@ -74,7 +75,7 @@ type CommandTest struct {
type Input struct {
// If specified, the procedure will be called with a pseudo-TTY. The console
// argument can be used to expect and send values to the TTY.
Procedure func(console *streams.Console)
Procedure func(console *console.Console)
}

type Output struct {
Expand Down Expand Up @@ -123,14 +124,14 @@ func (c *CommandTest) Run(t *testing.T) {
// Reference:
// https://github.com/AlecAivazis/survey/blob/93657ef69381dd1ffc7a4a9cfe5a2aefff4ca4ad/survey_posix_test.go#L15
func (c *CommandTest) runCommand(t *testing.T, iostreams genericclioptions.IOStreams) bool {
console, err := streams.NewConsole(iostreams.Out)
console, err := console.NewConsole(iostreams.Out)
if err != nil {
t.Fatalf("failed to create console: %v", err)
}
defer console.Close()

// Prepare root command.
command := cmd.NewRootCommand(streams.NewConsoleStreams(console))
command := cmd.NewRootCommand(streams.NewTTYStreams(console.Tty()))
command.SetArgs(c.Args)

// Pass input to the pty.
Expand Down

0 comments on commit 50c09fd

Please sign in to comment.