summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/future_test.go
diff options
context:
space:
mode:
authorinsomniac <insomniacslk@users.noreply.github.com>2018-08-14 15:22:10 +0100
committerGitHub <noreply@github.com>2018-08-14 15:22:10 +0100
commite14f9e09d34be98fddb8686af726d7e6692f2e3b (patch)
treebd3e20017a224d5def24db70388b1befa62d3bd3 /dhcpv6/future_test.go
parent35ed68606514ab77a523f72b103474e36361bcf7 (diff)
parent1c12a97ec2674a36612ddb4a4a627d407ee38b46 (diff)
Move DHCPv6 async to separate package (#127)
Diffstat (limited to 'dhcpv6/future_test.go')
-rw-r--r--dhcpv6/future_test.go170
1 files changed, 0 insertions, 170 deletions
diff --git a/dhcpv6/future_test.go b/dhcpv6/future_test.go
deleted file mode 100644
index bee87e3..0000000
--- a/dhcpv6/future_test.go
+++ /dev/null
@@ -1,170 +0,0 @@
-package dhcpv6
-
-import (
- "errors"
- "testing"
- "time"
-
- "github.com/stretchr/testify/require"
-)
-
-func TestResponseValue(t *testing.T) {
- m, err := NewMessage()
- require.NoError(t, err)
- r := NewResponse(m, nil)
- require.Equal(t, r.Value(), m)
- require.Equal(t, r.Error(), nil)
-}
-
-func TestResponseError(t *testing.T) {
- e := errors.New("Test error")
- r := NewResponse(nil, e)
- require.Equal(t, r.Value(), nil)
- require.Equal(t, r.Error(), e)
-}
-
-func TestSuccessFuture(t *testing.T) {
- m, err := NewMessage()
- require.NoError(t, err)
- f := NewSuccessFuture(m)
-
- val, err := f.Wait()
- require.NoError(t, err)
- require.Equal(t, val, m)
-}
-
-func TestFailureFuture(t *testing.T) {
- e := errors.New("Test error")
- f := NewFailureFuture(e)
-
- val, err := f.Wait()
- require.Equal(t, err, e)
- require.Equal(t, val, nil)
-}
-
-func TestThenSuccess(t *testing.T) {
- m, err := NewMessage()
- require.NoError(t, err)
- s, err := NewMessage()
- require.NoError(t, err)
- e := errors.New("Test error")
-
- f := NewSuccessFuture(m).
- Then(func(_ DHCPv6) Future {
- return NewSuccessFuture(s)
- }, func(_ error) Future {
- return NewFailureFuture(e)
- })
-
- val, err := f.Wait()
- require.NoError(t, err)
- require.NotEqual(t, val, m)
- require.Equal(t, val, s)
-}
-
-func TestThenFailure(t *testing.T) {
- m, err := NewMessage()
- require.NoError(t, err)
- s, err := NewMessage()
- require.NoError(t, err)
- e := errors.New("Test error")
- e2 := errors.New("Test error 2")
-
- f := NewFailureFuture(e).
- Then(func(_ DHCPv6) Future {
- return NewSuccessFuture(s)
- }, func(_ error) Future {
- return NewFailureFuture(e2)
- })
-
- val, err := f.Wait()
- require.Error(t, err)
- require.NotEqual(t, val, m)
- require.NotEqual(t, val, s)
- require.NotEqual(t, err, e)
- require.Equal(t, err, e2)
-}
-
-func TestOnSuccess(t *testing.T) {
- m, err := NewMessage()
- require.NoError(t, err)
- s, err := NewMessage()
- require.NoError(t, err)
-
- f := NewSuccessFuture(m).
- OnSuccess(func(_ DHCPv6) Future {
- return NewSuccessFuture(s)
- })
-
- val, err := f.Wait()
- require.NoError(t, err)
- require.NotEqual(t, val, m)
- require.Equal(t, val, s)
-}
-
-func TestOnSuccessForFailureFuture(t *testing.T) {
- m, err := NewMessage()
- require.NoError(t, err)
- e := errors.New("Test error")
-
- f := NewFailureFuture(e).
- OnSuccess(func(_ DHCPv6) Future {
- return NewSuccessFuture(m)
- })
-
- val, err := f.Wait()
- require.Error(t, err)
- require.Equal(t, err, e)
- require.NotEqual(t, val, m)
-}
-
-func TestOnFailure(t *testing.T) {
- m, err := NewMessage()
- require.NoError(t, err)
- s, err := NewMessage()
- require.NoError(t, err)
- e := errors.New("Test error")
-
- f := NewFailureFuture(e).
- OnFailure(func(_ error) Future {
- return NewSuccessFuture(s)
- })
-
- val, err := f.Wait()
- require.NoError(t, err)
- require.NotEqual(t, val, m)
- require.Equal(t, val, s)
-}
-
-func TestOnFailureForSuccessFuture(t *testing.T) {
- m, err := NewMessage()
- require.NoError(t, err)
- s, err := NewMessage()
- require.NoError(t, err)
-
- f := NewSuccessFuture(m).
- OnFailure(func(_ error) Future {
- return NewSuccessFuture(s)
- })
-
- val, err := f.Wait()
- require.NoError(t, err)
- require.NotEqual(t, val, s)
- require.Equal(t, val, m)
-}
-
-func TestWaitTimeout(t *testing.T) {
- m, err := NewMessage()
- require.NoError(t, err)
- s, err := NewMessage()
- require.NoError(t, err)
- f := NewSuccessFuture(m).OnSuccess(func(_ DHCPv6) Future {
- time.Sleep(1 * time.Second)
- return NewSuccessFuture(s)
- })
- val, err := f.WaitTimeout(50 * time.Millisecond)
- require.Error(t, err)
- require.Equal(t, err.Error(), "Timed out")
- require.NotEqual(t, val, m)
- require.NotEqual(t, val, s)
-}