forked from centrifugal/centrifuge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
176 additions
and
65 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
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
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,36 @@ | ||
package cancelctx | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCustomContext(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
ch := make(chan struct{}) | ||
customCtx := New(ctx, ch) | ||
require.NoError(t, customCtx.Err()) | ||
dlTime, dlSet := customCtx.Deadline() | ||
require.Zero(t, dlTime) | ||
require.False(t, dlSet) | ||
select { | ||
case <-customCtx.Done(): | ||
require.Fail(t, "must not be cancelled") | ||
default: | ||
} | ||
cancel() | ||
select { | ||
case <-customCtx.Done(): | ||
require.Fail(t, "must not be cancelled") | ||
default: | ||
} | ||
close(ch) | ||
select { | ||
case <-customCtx.Done(): | ||
require.Equal(t, context.Canceled, customCtx.Err()) | ||
default: | ||
require.Fail(t, "must be cancelled") | ||
} | ||
} |
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,24 @@ | ||
package clientproto | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/centrifugal/protocol" | ||
) | ||
|
||
func TestPushHelpers(t *testing.T) { | ||
msg := NewMessagePush(protocol.Raw("{}")) | ||
require.NotNil(t, msg) | ||
msg = NewJoinPush("test", protocol.Raw("{}")) | ||
require.NotNil(t, msg) | ||
msg = NewLeavePush("test", protocol.Raw("{}")) | ||
require.NotNil(t, msg) | ||
msg = NewPublicationPush("test", protocol.Raw("{}")) | ||
require.NotNil(t, msg) | ||
msg = NewSubPush("test", protocol.Raw("{}")) | ||
require.NotNil(t, msg) | ||
msg = NewUnsubPush("test", protocol.Raw("{}")) | ||
require.NotNil(t, msg) | ||
} |
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,68 @@ | ||
package controlproto | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCommandProtoExtra(t *testing.T) { | ||
msg := &Command{ | ||
UID: "test", | ||
Method: MethodTypeDisconnect, | ||
Params: Raw("{}"), | ||
} | ||
|
||
d, b := msg.Method.EnumDescriptor() | ||
require.Equal(t, fileDescriptorControl, d) | ||
require.Equal(t, []int{0}, b) | ||
|
||
require.Equal(t, "test", msg.GetUID()) | ||
require.Equal(t, MethodTypeDisconnect, msg.GetMethod()) | ||
require.NotZero(t, msg.String()) | ||
} | ||
|
||
func TestNodeProtoExtra(t *testing.T) { | ||
msg := &Node{ | ||
UID: "test", | ||
Name: "test name", | ||
Version: "v1.0.0", | ||
NumChannels: 2, | ||
NumClients: 3, | ||
NumUsers: 1, | ||
Uptime: 12, | ||
Metrics: &Metrics{ | ||
Interval: 60, | ||
Items: map[string]float64{ | ||
"item": 1, | ||
}, | ||
}, | ||
} | ||
require.Equal(t, "test", msg.GetUID()) | ||
require.Equal(t, "test name", msg.GetName()) | ||
require.Equal(t, "v1.0.0", msg.GetVersion()) | ||
require.Equal(t, uint32(2), msg.GetNumChannels()) | ||
require.Equal(t, uint32(1), msg.GetNumUsers()) | ||
require.Equal(t, uint32(3), msg.GetNumClients()) | ||
require.Equal(t, uint32(12), msg.GetUptime()) | ||
require.NotNil(t, msg.GetMetrics()) | ||
require.NotZero(t, msg.String()) | ||
} | ||
|
||
func TestDisconnectProtoExtra(t *testing.T) { | ||
msg := &Disconnect{ | ||
User: "test", | ||
} | ||
require.Equal(t, "test", msg.GetUser()) | ||
require.NotZero(t, msg.String()) | ||
} | ||
|
||
func TestUnsubscribeProtoExtra(t *testing.T) { | ||
msg := &Unsubscribe{ | ||
User: "test", | ||
Channel: "test channel", | ||
} | ||
require.Equal(t, "test", msg.GetUser()) | ||
require.Equal(t, "test channel", msg.GetChannel()) | ||
require.NotZero(t, msg.String()) | ||
} |
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