File: controlpb_extra_test.go

package info (click to toggle)
golang-github-centrifugal-centrifuge 0.15.0%2Bgit20210306.f435ba2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,612 kB
  • sloc: javascript: 102; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 1,579 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
package controlpb

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())
}