From ee36bd892571d93e758330a3eba844923c9d8e14 Mon Sep 17 00:00:00 2001 From: cuteLittleDevil <792192820@qq.com> Date: Wed, 25 Oct 2023 22:32:00 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E5=A4=8Dps=E5=92=8Chls?= =?UTF-8?q?=E6=8B=89=E6=B5=81=E6=97=B6=20/api/stat/all=5Fgroup=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=8E=B7=E5=8F=96=E6=B5=81=E5=8D=8F=E8=AE=AE=E7=AD=89?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E4=B8=BA=E7=A9=BA=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/base/basic_session_stat.go | 10 ++ pkg/base/basic_session_stat_test.go | 198 ++++++++++++++++++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 pkg/base/basic_session_stat_test.go diff --git a/pkg/base/basic_session_stat.go b/pkg/base/basic_session_stat.go index c6776f6e..37facca4 100644 --- a/pkg/base/basic_session_stat.go +++ b/pkg/base/basic_session_stat.go @@ -82,6 +82,16 @@ func NewBasicSessionStat(sessionType SessionType, remoteAddr string) BasicSessio s.stat.SessionId = GenUkPsPubSession() s.stat.BaseType = SessionBaseTypePubStr s.stat.Protocol = SessionProtocolPsStr + case SessionTypeHlsSub: + s.stat.SessionId = GenUkHlsSubSession() + s.stat.BaseType = SessionBaseTypeSubStr + s.stat.Protocol = SessionProtocolHlsStr + case SessionTypeTsSub: + s.stat.SessionId = GenUkTsSubSession() + s.stat.BaseType = SessionBaseTypeSubStr + s.stat.Protocol = SessionProtocolTsStr + default: + nazalog.Errorf("unknown session type: [d%]", sessionType) } return s } diff --git a/pkg/base/basic_session_stat_test.go b/pkg/base/basic_session_stat_test.go new file mode 100644 index 00000000..cbeb0626 --- /dev/null +++ b/pkg/base/basic_session_stat_test.go @@ -0,0 +1,198 @@ +package base + +import ( + "testing" +) + +func TestNewBasicSessionStat(t *testing.T) { + type args struct { + sessionType SessionType + remoteAddr string + } + tests := []struct { + name string + args args + want BasicSessionStat + }{ + { + name: "rtmp_server", + args: args{ + sessionType: SessionTypeRtmpServerSession, + }, + want: BasicSessionStat{ + stat: StatSession{ + SessionId: GenUkRtmpServerSession(), + BaseType: SessionBaseTypePubSubStr, + Protocol: SessionProtocolRtmpStr, + }, + }, + }, + { + name: "rtmp_push", + args: args{ + sessionType: SessionTypeRtmpPush, + }, + want: BasicSessionStat{ + stat: StatSession{ + SessionId: GenUkRtmpPushSession(), + BaseType: SessionBaseTypePushStr, + Protocol: SessionProtocolRtmpStr, + }, + }, + }, + { + name: "rtmp_pull", + args: args{ + sessionType: SessionTypeRtmpPull, + }, + want: BasicSessionStat{ + stat: StatSession{ + SessionId: GenUkRtmpPullSession(), + BaseType: SessionBaseTypePullStr, + Protocol: SessionProtocolRtmpStr, + }, + }, + }, + { + name: "rtsp_pub", + args: args{ + sessionType: SessionTypeRtspPub, + }, + want: BasicSessionStat{ + stat: StatSession{ + SessionId: GenUkRtspPubSession(), + BaseType: SessionBaseTypePubStr, + Protocol: SessionProtocolRtspStr, + }, + }, + }, + { + name: "rtsp_sub", + args: args{ + sessionType: SessionTypeRtspSub, + }, + want: BasicSessionStat{ + stat: StatSession{ + SessionId: GenUkRtspSubSession(), + BaseType: SessionBaseTypeSubStr, + Protocol: SessionProtocolRtspStr, + }, + }, + }, + { + name: "rtsp_push", + args: args{ + sessionType: SessionTypeRtspPush, + }, + want: BasicSessionStat{ + stat: StatSession{ + SessionId: GenUkRtspPushSession(), + BaseType: SessionBaseTypePushStr, + Protocol: SessionProtocolRtspStr, + }, + }, + }, + { + name: "rtsp_pull", + args: args{ + sessionType: SessionTypeRtspPull, + }, + want: BasicSessionStat{ + stat: StatSession{ + SessionId: GenUkRtspPullSession(), + BaseType: SessionBaseTypePullStr, + Protocol: SessionProtocolRtspStr, + }, + }, + }, + { + name: "flv_sub", + args: args{ + sessionType: SessionTypeFlvSub, + }, + want: BasicSessionStat{ + stat: StatSession{ + SessionId: GenUkFlvSubSession(), + BaseType: SessionBaseTypeSubStr, + Protocol: SessionProtocolFlvStr, + }, + }, + }, + { + name: "ps_pub", + args: args{ + sessionType: SessionTypePsPub, + }, + want: BasicSessionStat{ + stat: StatSession{ + SessionId: GenUkPsPubSession(), + BaseType: SessionBaseTypePubStr, + Protocol: SessionProtocolPsStr, + }, + }, + }, + { + name: "ts_sub", + args: args{ + sessionType: SessionTypeTsSub, + }, + want: BasicSessionStat{ + stat: StatSession{ + SessionId: GenUkTsSubSession(), + BaseType: SessionBaseTypeSubStr, + Protocol: SessionProtocolTsStr, + }, + }, + }, + { + name: "hls_sub", + args: args{ + sessionType: SessionTypeHlsSub, + }, + want: BasicSessionStat{ + stat: StatSession{ + SessionId: GenUkHlsSubSession(), + BaseType: SessionBaseTypeSubStr, + Protocol: SessionProtocolHlsStr, + }, + }, + }, + { + name: "customize_pub", + args: args{ + sessionType: SessionTypeCustomizePub, + }, + want: BasicSessionStat{ + stat: StatSession{ + SessionId: "", + BaseType: "", + Protocol: "", + }, + }, + }, + { + name: "other", + args: args{ + sessionType: -1, + }, + want: BasicSessionStat{ + stat: StatSession{ + SessionId: "", + BaseType: "", + Protocol: "", + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := NewBasicSessionStat(tt.args.sessionType, tt.args.remoteAddr) + if got.stat.Protocol != tt.want.stat.Protocol { + t.Errorf("NewBasicSessionStat() Protocol = %s, want %s", got.stat.Protocol, tt.want.stat.Protocol) + } + if got.stat.BaseType != tt.want.stat.BaseType { + t.Errorf("NewBasicSessionStat() BaseType = %s, want %s", got.stat.BaseType, tt.want.stat.BaseType) + } + }) + } +}