| 1 |
package httpexec |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
import ( |
| 7 |
"context" |
| 8 |
"testing" |
| 9 |
|
| 10 |
"github.com/mesos/mesos-go/api/v1/lib" |
| 11 |
"github.com/mesos/mesos-go/api/v1/lib/client" |
| 12 |
"github.com/mesos/mesos-go/api/v1/lib/httpcli" |
| 13 |
|
| 14 |
"github.com/mesos/mesos-go/api/v1/lib/executor" |
| 15 |
"github.com/mesos/mesos-go/api/v1/lib/executor/calls" |
| 16 |
) |
| 17 |
|
| 18 |
func TestNewSender(t *testing.T) { |
| 19 |
ch := make(chan client.Request, 1) |
| 20 |
cf := ClientFunc(func(r client.Request, _ client.ResponseClass, _ ...httpcli.RequestOpt) (_ mesos.Response, _ error) { |
| 21 |
ch <- r |
| 22 |
return |
| 23 |
}) |
| 24 |
check := func(_ mesos.Response, err error) { |
| 25 |
if err != nil { |
| 26 |
t.Fatal(err) |
| 27 |
} |
| 28 |
} |
| 29 |
sent := func() client.Request { |
| 30 |
select { |
| 31 |
case r := <-ch: |
| 32 |
return r |
| 33 |
default: |
| 34 |
t.Fatal("no request was sent") |
| 35 |
} |
| 36 |
return nil |
| 37 |
} |
| 38 |
sender := NewSender(cf) |
| 39 |
c := &executor.Call{Type:executor.Call_MESSAGE} |
| 40 |
|
| 41 |
check(sender.Send(context.Background(), calls.NonStreaming(c))) |
| 42 |
r := sent() |
| 43 |
if _, ok := r.(client.RequestStreaming); ok { |
| 44 |
t.Fatalf("expected non-streaming request instead of %v", r) |
| 45 |
} |
| 46 |
|
| 47 |
check(sender.Send(context.Background(), calls.Empty().Push(c))) |
| 48 |
r = sent() |
| 49 |
if _, ok := r.(client.RequestStreaming); !ok { |
| 50 |
t.Fatalf("expected streaming request instead of %v", r) |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
_, err := sender.Send(context.Background(), calls.Empty().Push(new(executor.Call))) |
| 56 |
if err == nil { |
| 57 |
t.Fatal("expected send to fail w/ malformed call") |
| 58 |
} |
| 59 |
} |