Skip to content

Commit

Permalink
cmds/legacy: update-related changes
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: keks <keks@cryptoscope.co>
  • Loading branch information
keks committed Jun 29, 2018
1 parent 2efffcb commit 91b1be3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 8 deletions.
58 changes: 57 additions & 1 deletion commands/legacy/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestNewCommand(t *testing.T) {
}

func TestPipePair(t *testing.T) {
cmd := &cmds.Command{Type: "string"}
cmd := NewCommand(&oldcmds.Command{Type: "string"})

req, err := cmds.NewRequest(context.TODO(), nil, nil, nil, nil, cmd)
if err != nil {
Expand All @@ -134,6 +134,11 @@ func TestPipePair(t *testing.T) {
t.Fatal(err)
}

err = re.Close()
if err != nil {
t.Fatal(err)
}

close(wait)
}()

Expand All @@ -149,6 +154,57 @@ func TestPipePair(t *testing.T) {
t.Fatalf("expected value %#v but got %#v", expect, v)
}

_, err = res.Next()
if err != io.EOF {
t.Fatal("expected io.EOF, got:", err)
}

<-wait
}

func TestChanPair(t *testing.T) {
cmd := NewCommand(&oldcmds.Command{Type: "string"})

req, err := cmds.NewRequest(context.TODO(), nil, nil, nil, nil, cmd)
if err != nil {
t.Fatal(err)
}

re, res := cmds.NewChanResponsePair(req)

wait := make(chan interface{})

expect := "abc"
go func() {
err := re.Emit(expect)
if err != nil {
t.Fatal(err)
}

err = re.Close()
if err != nil {
t.Fatal(err)
}

close(wait)
}()

v, err := res.Next()
if err != nil {
t.Fatal(err)
}
str, ok := v.(string)
if !ok {
t.Fatalf("expected type %T but got %T", expect, v)
}
if str != expect {
t.Fatalf("expected value %#v but got %#v", expect, v)
}

_, err = res.Next()
if err != io.EOF {
t.Fatal("expected io.EOF, got:", err)
}

<-wait
}
11 changes: 4 additions & 7 deletions commands/legacy/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,13 @@ func (r *fakeResponse) Send(errCh chan<- error) {
defer close(errCh)

out := r.Output()
if out == nil {
return
}

if ch, ok := out.(chan interface{}); ok {
out = (<-chan interface{})(ch)
// don't emit nil or Single{nil}
if out == nil || out == (cmds.Single{nil}) {
return
}

err := r.re.Emit(out)
errCh <- err
errCh <- r.re.Emit(out)
return
}

Expand Down

0 comments on commit 91b1be3

Please sign in to comment.