From c5e6e848069ae1d419fa78054ca5bf010e816e94 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 11 Dec 2020 16:50:11 -0800 Subject: [PATCH] remove iochan package from sdk, switch to using its descendent, mitchellh/iochan --- packer-plugin-sdk/iochan/iochan.go | 30 ------------------- packer-plugin-sdk/iochan/iochan_test.go | 28 ----------------- packer-plugin-sdk/json/unmarshal_test.go | 1 - packer-plugin-sdk/packer/communicator_test.go | 6 ++-- .../shell-local/localexec/run_and_stream.go | 6 ++-- 5 files changed, 6 insertions(+), 65 deletions(-) delete mode 100644 packer-plugin-sdk/iochan/iochan.go delete mode 100644 packer-plugin-sdk/iochan/iochan_test.go delete mode 100644 packer-plugin-sdk/json/unmarshal_test.go diff --git a/packer-plugin-sdk/iochan/iochan.go b/packer-plugin-sdk/iochan/iochan.go deleted file mode 100644 index 4f3f7d8e6..000000000 --- a/packer-plugin-sdk/iochan/iochan.go +++ /dev/null @@ -1,30 +0,0 @@ -// Package iochan is a Go library for treating `io` readers and writers like -// channels. -package iochan - -import ( - "bufio" - "io" -) - -// LineReader takes an io.Reader and produces the contents of the reader on the -// returned channel. Internally bufio.NewScanner is used, io.ScanLines parses -// lines and returns them without carriage return. Scan can panic if the split -// function returns too many empty tokens without advancing the input. -// -// The channel will be closed either by reaching the end of the input or an -// error. -func LineReader(r io.Reader) <-chan string { - ch := make(chan string) - - go func() { - scanner := bufio.NewScanner(r) - defer close(ch) - - for scanner.Scan() { - ch <- scanner.Text() - } - }() - - return ch -} diff --git a/packer-plugin-sdk/iochan/iochan_test.go b/packer-plugin-sdk/iochan/iochan_test.go deleted file mode 100644 index a600aca0a..000000000 --- a/packer-plugin-sdk/iochan/iochan_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package iochan - -import ( - "bytes" - "reflect" - "strings" - "testing" -) - -func TestLineReader(t *testing.T) { - - data := []string{"foo", "bar", "baz"} - - buf := new(bytes.Buffer) - buf.WriteString(strings.Join(data, "\n") + "\n") - - ch := LineReader(buf) - - var result []string - expected := data - for v := range ch { - result = append(result, v) - } - - if !reflect.DeepEqual(result, expected) { - t.Fatalf("unexpected results: %#v", result) - } -} diff --git a/packer-plugin-sdk/json/unmarshal_test.go b/packer-plugin-sdk/json/unmarshal_test.go deleted file mode 100644 index a5b981cc6..000000000 --- a/packer-plugin-sdk/json/unmarshal_test.go +++ /dev/null @@ -1 +0,0 @@ -package json diff --git a/packer-plugin-sdk/packer/communicator_test.go b/packer-plugin-sdk/packer/communicator_test.go index 40450e98e..e334d0d52 100644 --- a/packer-plugin-sdk/packer/communicator_test.go +++ b/packer-plugin-sdk/packer/communicator_test.go @@ -9,7 +9,7 @@ import ( "time" "github.com/google/go-cmp/cmp" - "github.com/hashicorp/packer/packer-plugin-sdk/iochan" + "github.com/mitchellh/iochan" "golang.org/x/sync/errgroup" ) @@ -42,8 +42,8 @@ func TestRemoteCmd_StartWithUi(t *testing.T) { testPrintFn := func(in io.Reader, expected []string) error { i := 0 got := []string{} - for output := range iochan.LineReader(in) { - got = append(got, output) + for output := range iochan.DelimReader(in, '\n') { + got = append(got, strings.TrimSpace(output)) i++ if i == len(expected) { // here ideally the LineReader chan should be closed, but since diff --git a/packer-plugin-sdk/shell-local/localexec/run_and_stream.go b/packer-plugin-sdk/shell-local/localexec/run_and_stream.go index 9555d2660..81e6af526 100644 --- a/packer-plugin-sdk/shell-local/localexec/run_and_stream.go +++ b/packer-plugin-sdk/shell-local/localexec/run_and_stream.go @@ -10,8 +10,8 @@ import ( "sync" "syscall" - "github.com/hashicorp/packer/packer-plugin-sdk/iochan" packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer" + "github.com/mitchellh/iochan" ) // RunAndStream allows you to run a local command and stream output to the UI. @@ -39,8 +39,8 @@ func RunAndStream(cmd *exec.Cmd, ui packersdk.Ui, sensitive []string) error { // Create the channels we'll use for data exitCh := make(chan int, 1) - stdoutCh := iochan.LineReader(stdout_r) - stderrCh := iochan.LineReader(stderr_r) + stdoutCh := iochan.DelimReader(stdout_r, '\n') + stderrCh := iochan.DelimReader(stderr_r, '\n') // Start the goroutine to watch for the exit go func() {