| 1 |
package httpsched |
| 2 |
|
| 3 |
import ( |
| 4 |
"errors" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"github.com/mesos/mesos-go/api/v1/lib/encoding" |
| 8 |
"github.com/mesos/mesos-go/api/v1/lib/extras/latch" |
| 9 |
"github.com/mesos/mesos-go/api/v1/lib/scheduler" |
| 10 |
) |
| 11 |
|
| 12 |
func TestDisconnectionDecoder(t *testing.T) { |
| 13 |
|
| 14 |
|
| 15 |
expected := errors.New("unmarshaler error") |
| 16 |
decoder := encoding.DecoderFunc(func(_ encoding.Unmarshaler) error { return expected }) |
| 17 |
latch := new(latch.L).Reset() |
| 18 |
|
| 19 |
d := disconnectionDecoder(decoder, latch.Close) |
| 20 |
err := d.Decode(nil) |
| 21 |
if err != expected { |
| 22 |
t.Errorf("expected %v instead of %v", expected, err) |
| 23 |
} |
| 24 |
if !latch.Closed() { |
| 25 |
t.Error("disconnect func was not called") |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
latch.Reset() |
| 30 |
errtype := scheduler.Event_ERROR |
| 31 |
event := &scheduler.Event{Type: errtype} |
| 32 |
decoder = encoding.DecoderFunc(func(um encoding.Unmarshaler) error { return nil }) |
| 33 |
d = disconnectionDecoder(decoder, latch.Close) |
| 34 |
_ = d.Decode(event) |
| 35 |
if !latch.Closed() { |
| 36 |
t.Error("disconnect func was not called") |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
latch.Reset() |
| 41 |
errtype = scheduler.Event_SUBSCRIBED |
| 42 |
event = &scheduler.Event{Type: errtype} |
| 43 |
_ = d.Decode(event) |
| 44 |
if latch.Closed() { |
| 45 |
t.Error("disconnect func was unexpectedly called") |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
latch.Reset() |
| 50 |
nonEvent := &scheduler.Call{} |
| 51 |
_ = d.Decode(nonEvent) |
| 52 |
if !latch.Closed() { |
| 53 |
t.Error("disconnect func was not called") |
| 54 |
} |
| 55 |
} |