File: calls_sender_generated_test.go

package info (click to toggle)
golang-github-mesos-mesos-go 0.0.6%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 11,724 kB
  • sloc: makefile: 163
file content (128 lines) | stat: -rw-r--r-- 2,996 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package calls

// 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
// GENERATED CODE FOLLOWS; DO NOT EDIT.

import (
	"context"
	"testing"

	"github.com/mesos/mesos-go/api/v1/lib"

	"github.com/mesos/mesos-go/api/v1/lib/executor"
)

func TestNonStreaming(t *testing.T) {
	c := new(executor.Call)
	f := NonStreaming(c)
	if x := f.Call(); x != c {
		t.Fatalf("expected %#v instead of %#v", c, x)
	}
	if x := f.Marshaler(); x == nil {
		t.Fatal("expected non-nil Marshaler")
	}
	f = NonStreaming(nil)
	if x := f.Marshaler(); x != nil {
		t.Fatalf("expected nil Marshaler instead of %#v", x)
	}
}

func TestStreaming(t *testing.T) {
	f := Empty()

	f.IsStreaming()

	if x := f.Call(); x != nil {
		t.Fatalf("expected nil Call instead of %#v", x)
	}
	if x := f.Marshaler(); x != nil {
		t.Fatalf("expected nil Call instead of %#v", x)
	}

	c := new(executor.Call)

	f = f.Push(c)
	if x := f.Marshaler(); x == nil {
		t.Fatal("expected non-nil Marshaler")
	}
	if x := f.Marshaler(); x != nil {
		t.Fatalf("expected nil Marshaler instead of %#v", x)
	}

	c2 := new(executor.Call)

	f = Empty().Push(c, c2)
	if x := f.Call(); x != c {
		t.Fatalf("expected %#v instead of %#v", c, x)
	}
	if x := f.Call(); x != c2 {
		t.Fatalf("expected %#v instead of %#v", c2, x)
	}
	if x := f.Call(); x != nil {
		t.Fatalf("expected nil Call instead of %#v", x)
	}

	ch := make(chan *executor.Call, 2)
	ch <- c
	ch <- c2
	close(ch)
	f = FromChan(ch)
	if x := f.Call(); x != c {
		t.Fatalf("expected %#v instead of %#v", c, x)
	}
	if x := f.Call(); x != c2 {
		t.Fatalf("expected %#v instead of %#v", c2, x)
	}
	if x := f.Call(); x != nil {
		t.Fatalf("expected nil Call instead of %#v", x)
	}

	f = FromChan(nil)
	if x := f.Call(); x != nil {
		t.Fatalf("expected nil Call instead of %#v", x)
	}
}

func TestIgnoreResponse(t *testing.T) {
	var closed bool

	IgnoreResponse(SenderFunc(func(_ context.Context, _ Request) (mesos.Response, error) {
		return &mesos.ResponseWrapper{Closer: mesos.CloseFunc(func() error {
			closed = true
			return nil
		})}, nil
	})).Send(nil, nil)

	if !closed {
		t.Fatal("expected response to be closed")
	}
}

func TestSenderWith(t *testing.T) {
	var (
		s = SenderFunc(func(_ context.Context, r Request) (mesos.Response, error) {
			_ = r.Call() // need to invoke this to invoke SenderWith call decoration
			return nil, nil
		})
		ignore = func(_ mesos.Response, _ error) {}
		c = new(executor.Call)
	)

	for ti, tc := range []Request{NonStreaming(c), Empty().Push(c, c)} {
		var (
			invoked bool
			opt = func(c *executor.Call) { invoked = true }
		)

		// sanity check (w/o any options)
		ignore(SenderWith(s).Send(context.Background(), tc))
		if invoked {
			t.Fatalf("test case %d failed: unexpected option invocation", ti)
		}

		ignore(SenderWith(s, opt).Send(context.Background(), tc))
		if !invoked {
			t.Fatalf("test case %d failed: expected option invocation", ti)
		}
	}
}