File: metrics_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: bullseye, forky, sid, trixie
  • size: 11,724 kB
  • sloc: makefile: 163
file content (71 lines) | stat: -rw-r--r-- 1,959 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
package callrules

// go generate -import github.com/mesos/mesos-go/api/v1/lib -import github.com/mesos/mesos-go/api/v1/lib/scheduler -type E:*scheduler.Call:&scheduler.Call{} -type ET:scheduler.Call_Type -type Z:mesos.Response:&mesos.ResponseWrapper{} -output metrics_generated.go
// GENERATED CODE FOLLOWS; DO NOT EDIT.

import (
	"context"
	"errors"
	"reflect"
	"testing"

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

func TestMetrics(t *testing.T) {
	var (
		i   int
		ctx = context.Background()
		p   = &scheduler.Call{}
		a   = errors.New("a")
		h   = func(f func() error, _ ...string) error {
			i++
			return f()
		}
	)
	var zp = &mesos.ResponseWrapper{}
	for ti, tc := range []struct {
		ctx context.Context
		e   *scheduler.Call
		z   mesos.Response
		err error
	}{
		{ctx, p, zp, a},
		{ctx, p, zp, nil},
		
		{ctx, p, nil, a},
		{ctx, nil, zp, a},
	} {
		for ri, r := range []Rule{
			Metrics(h, nil), // default labeler
			Metrics(h, func(_ context.Context, _ *scheduler.Call) []string { return nil }), // custom labeler
		} {
			c, e, z, err := r.Eval(tc.ctx, tc.e, tc.z, tc.err, ChainIdentity)
			if !reflect.DeepEqual(c, tc.ctx) {
				t.Errorf("test case %d: expected context %q instead of %q", ti, tc.ctx, c)
			}
			if !reflect.DeepEqual(e, tc.e) {
				t.Errorf("test case %d: expected event %q instead of %q", ti, tc.e, e)
			}
			if !reflect.DeepEqual(z, tc.z) {
				t.Errorf("expected return object %q instead of %q", z, tc.z)
			}
			if !reflect.DeepEqual(err, tc.err) {
				t.Errorf("test case %d: expected error %q instead of %q", ti, tc.err, err)
			}
			if y := (ti * 2) + ri + 1; y != i {
				t.Errorf("test case %d: expected count %q instead of %q", ti, y, i)
			}
		}
	}
	func() {
		defer func() {
			if x := recover(); x != nil {
				t.Log("intercepted expected panic", x)
			}
		}()
		_ = Metrics(nil, nil)
		t.Fatalf("expected a panic because nil harness is not allowed")
	}()
}