File: httpmaster_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 (59 lines) | stat: -rw-r--r-- 1,711 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
package httpmaster

// go generate -import github.com/mesos/mesos-go/api/v1/lib/master -import github.com/mesos/mesos-go/api/v1/lib/master/calls -type C:master.Call:master.Call{Type:master.Call_GET_METRICS}
// 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/client"
	"github.com/mesos/mesos-go/api/v1/lib/httpcli"

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

func TestNewSender(t *testing.T) {
	ch := make(chan client.Request, 1)
	cf := ClientFunc(func(r client.Request, _ client.ResponseClass, _ ...httpcli.RequestOpt) (_ mesos.Response, _ error) {
		ch <- r
		return
	})
	check := func(_ mesos.Response, err error) {
		if err != nil {
			t.Fatal(err)
		}
	}
	sent := func() client.Request {
		select {
		case r := <-ch:
			return r
		default:
			t.Fatal("no request was sent")
		}
		return nil
	}
	sender := NewSender(cf)
	c := &master.Call{Type:master.Call_GET_METRICS}

	check(sender.Send(context.Background(), calls.NonStreaming(c)))
	r := sent()
	if _, ok := r.(client.RequestStreaming); ok {
		t.Fatalf("expected non-streaming request instead of %v", r)
	}

	check(sender.Send(context.Background(), calls.Empty().Push(c)))
	r = sent()
	if _, ok := r.(client.RequestStreaming); !ok {
		t.Fatalf("expected streaming request instead of %v", r)
	}

	// expect this to fail because newly created call structs don't have a type
	// that can be used for classifying an expected response type.
	_, err := sender.Send(context.Background(), calls.Empty().Push(new(master.Call)))
	if err == nil {
		t.Fatal("expected send to fail w/ malformed call")
	}
}