Debian Codegraph @

api/v1/lib/executor/calls/calls_sender_generated_test.go

raw symbols SCIP
1 package calls
2
3 // go generate -import github.com/mesos/mesos-go/api/v1/lib/executor -type C:executor.Call -type O:executor.CallOpt -output calls_sender_generated.go
4 // GENERATED CODE FOLLOWS; DO NOT EDIT.
5
6 import (
7 "context"
8 "testing"
9
10 "github.com/mesos/mesos-go/api/v1/lib"
11
12 "github.com/mesos/mesos-go/api/v1/lib/executor"
13 )
14
15 func TestNonStreaming(t *testing.T) {
16 c := new(executor.Call)
17 f := NonStreaming(c)
18 if x := f.Call(); x != c {
19 t.Fatalf("expected %#v instead of %#v", c, x)
20 }
21 if x := f.Marshaler(); x == nil {
22 t.Fatal("expected non-nil Marshaler")
23 }
24 f = NonStreaming(nil)
25 if x := f.Marshaler(); x != nil {
26 t.Fatalf("expected nil Marshaler instead of %#v", x)
27 }
28 }
29
30 func TestStreaming(t *testing.T) {
31 f := Empty()
32
33 f.IsStreaming()
34
35 if x := f.Call(); x != nil {
36 t.Fatalf("expected nil Call instead of %#v", x)
37 }
38 if x := f.Marshaler(); x != nil {
39 t.Fatalf("expected nil Call instead of %#v", x)
40 }
41
42 c := new(executor.Call)
43
44 f = f.Push(c)
45 if x := f.Marshaler(); x == nil {
46 t.Fatal("expected non-nil Marshaler")
47 }
48 if x := f.Marshaler(); x != nil {
49 t.Fatalf("expected nil Marshaler instead of %#v", x)
50 }
51
52 c2 := new(executor.Call)
53
54 f = Empty().Push(c, c2)
55 if x := f.Call(); x != c {
56 t.Fatalf("expected %#v instead of %#v", c, x)
57 }
58 if x := f.Call(); x != c2 {
59 t.Fatalf("expected %#v instead of %#v", c2, x)
60 }
61 if x := f.Call(); x != nil {
62 t.Fatalf("expected nil Call instead of %#v", x)
63 }
64
65 ch := make(chan *executor.Call, 2)
66 ch <- c
67 ch <- c2
68 close(ch)
69 f = FromChan(ch)
70 if x := f.Call(); x != c {
71 t.Fatalf("expected %#v instead of %#v", c, x)
72 }
73 if x := f.Call(); x != c2 {
74 t.Fatalf("expected %#v instead of %#v", c2, x)
75 }
76 if x := f.Call(); x != nil {
77 t.Fatalf("expected nil Call instead of %#v", x)
78 }
79
80 f = FromChan(nil)
81 if x := f.Call(); x != nil {
82 t.Fatalf("expected nil Call instead of %#v", x)
83 }
84 }
85
86 func TestIgnoreResponse(t *testing.T) {
87 var closed bool
88
89 IgnoreResponse(SenderFunc(func(_ context.Context, _ Request) (mesos.Response, error) {
90 return &mesos.ResponseWrapper{Closer: mesos.CloseFunc(func() error {
91 closed = true
92 return nil
93 })}, nil
94 })).Send(nil, nil)
95
96 if !closed {
97 t.Fatal("expected response to be closed")
98 }
99 }
100
101 func TestSenderWith(t *testing.T) {
102 var (
103 s = SenderFunc(func(_ context.Context, r Request) (mesos.Response, error) {
104 _ = r.Call() // need to invoke this to invoke SenderWith call decoration
105 return nil, nil
106 })
107 ignore = func(_ mesos.Response, _ error) {}
108 c = new(executor.Call)
109 )
110
111 for ti, tc := range []Request{NonStreaming(c), Empty().Push(c, c)} {
112 var (
113 invoked bool
114 opt = func(c *executor.Call) { invoked = true }
115 )
116
117 // sanity check (w/o any options)
118 ignore(SenderWith(s).Send(context.Background(), tc))
119 if invoked {
120 t.Fatalf("test case %d failed: unexpected option invocation", ti)
121 }
122
123 ignore(SenderWith(s, opt).Send(context.Background(), tc))
124 if !invoked {
125 t.Fatalf("test case %d failed: expected option invocation", ti)
126 }
127 }
128 }