-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rules: initial unit test for rule-metric integration
- Loading branch information
James DeFelice
committed
Jun 14, 2017
1 parent
5e5bc8d
commit 90fe8a5
Showing
13 changed files
with
297 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
api/v1/lib/extras/executor/callrules/metrics_generated_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package callrules | ||
|
||
// go generate -import github.com/mesos/mesos-go/api/v1/lib -import github.com/mesos/mesos-go/api/v1/lib/executor -type E:*executor.Call:&executor.Call{} -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/executor" | ||
) | ||
|
||
func TestMetrics(t *testing.T) { | ||
var ( | ||
i int | ||
ctx = context.Background() | ||
p = &executor.Call{} | ||
a = errors.New("a") | ||
h = func(f func() error, _ ...string) error { | ||
i++ | ||
return f() | ||
} | ||
r = Metrics(h) | ||
) | ||
var zp = &mesos.ResponseWrapper{} | ||
for ti, tc := range []struct { | ||
ctx context.Context | ||
e *executor.Call | ||
z mesos.Response | ||
err error | ||
}{ | ||
{ctx, p, zp, a}, | ||
{ctx, p, zp, nil}, | ||
|
||
{ctx, p, nil, a}, | ||
{ctx, nil, zp, a}, | ||
} { | ||
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 + 1; y != i { | ||
t.Errorf("test case %d: expected count %q instead of %q", ti, y, i) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
api/v1/lib/extras/executor/eventrules/metrics_generated_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package eventrules | ||
|
||
// go generate -import github.com/mesos/mesos-go/api/v1/lib/executor -type E:*executor.Event:&executor.Event{} -output metrics_generated.go | ||
// GENERATED CODE FOLLOWS; DO NOT EDIT. | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/mesos/mesos-go/api/v1/lib/executor" | ||
) | ||
|
||
func TestMetrics(t *testing.T) { | ||
var ( | ||
i int | ||
ctx = context.Background() | ||
p = &executor.Event{} | ||
a = errors.New("a") | ||
h = func(f func() error, _ ...string) error { | ||
i++ | ||
return f() | ||
} | ||
r = Metrics(h) | ||
) | ||
for ti, tc := range []struct { | ||
ctx context.Context | ||
e *executor.Event | ||
err error | ||
}{ | ||
{ctx, p, a}, | ||
{ctx, p, nil}, | ||
{ctx, nil, a}, | ||
} { | ||
c, e, err := r.Eval(tc.ctx, tc.e, 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(err, tc.err) { | ||
t.Errorf("test case %d: expected error %q instead of %q", ti, tc.err, err) | ||
} | ||
if y := ti + 1; y != i { | ||
t.Errorf("test case %d: expected count %q instead of %q", ti, y, i) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
api/v1/lib/extras/scheduler/callrules/metrics_generated_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
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 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() | ||
} | ||
r = Metrics(h) | ||
) | ||
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}, | ||
} { | ||
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 + 1; y != i { | ||
t.Errorf("test case %d: expected count %q instead of %q", ti, y, i) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
api/v1/lib/extras/scheduler/eventrules/metrics_generated_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package eventrules | ||
|
||
// go generate -import github.com/mesos/mesos-go/api/v1/lib/scheduler -type E:*scheduler.Event:&scheduler.Event{} -output metrics_generated.go | ||
// GENERATED CODE FOLLOWS; DO NOT EDIT. | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/mesos/mesos-go/api/v1/lib/scheduler" | ||
) | ||
|
||
func TestMetrics(t *testing.T) { | ||
var ( | ||
i int | ||
ctx = context.Background() | ||
p = &scheduler.Event{} | ||
a = errors.New("a") | ||
h = func(f func() error, _ ...string) error { | ||
i++ | ||
return f() | ||
} | ||
r = Metrics(h) | ||
) | ||
for ti, tc := range []struct { | ||
ctx context.Context | ||
e *scheduler.Event | ||
err error | ||
}{ | ||
{ctx, p, a}, | ||
{ctx, p, nil}, | ||
{ctx, nil, a}, | ||
} { | ||
c, e, err := r.Eval(tc.ctx, tc.e, 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(err, tc.err) { | ||
t.Errorf("test case %d: expected error %q instead of %q", ti, tc.err, err) | ||
} | ||
if y := ti + 1; y != i { | ||
t.Errorf("test case %d: expected count %q instead of %q", ti, y, i) | ||
} | ||
} | ||
} |