From 98e6e8239e389268bc747b0e2fd105dd2888c830 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:51:07 +0200 Subject: [PATCH] simplify tests --- client_play_test.go | 9 +- pkg/headers/authenticate_test.go | 135 +++++++----------------------- pkg/headers/authorization_test.go | 15 +--- pkg/headers/range_test.go | 23 +++-- pkg/headers/transport_test.go | 23 ++--- 5 files changed, 60 insertions(+), 145 deletions(-) diff --git a/client_play_test.go b/client_play_test.go index d6e60530..d95a92b5 100644 --- a/client_play_test.go +++ b/client_play_test.go @@ -25,6 +25,10 @@ import ( "github.com/bluenviron/mediacommon/pkg/codecs/mpeg4audio" ) +func ipPtr(v net.IP) *net.IP { + return &v +} + func mustMarshalMedias(medias media.Medias) []byte { byts, err := medias.Marshal(false).Marshal() if err != nil { @@ -2818,10 +2822,7 @@ func TestClientPlayDifferentSource(t *testing.T) { Protocol: headers.TransportProtocolUDP, ClientPorts: inTH.ClientPorts, ServerPorts: &[2]int{34556, 34557}, - Source: func() *net.IP { - i := net.ParseIP("127.0.1.1") - return &i - }(), + Source: ipPtr(net.ParseIP("127.0.1.1")), } l1, err := net.ListenPacket("udp", "127.0.1.1:34556") diff --git a/pkg/headers/authenticate_test.go b/pkg/headers/authenticate_test.go index be35f9ee..86cf1cee 100644 --- a/pkg/headers/authenticate_test.go +++ b/pkg/headers/authenticate_test.go @@ -8,6 +8,10 @@ import ( "github.com/bluenviron/gortsplib/v3/pkg/base" ) +func stringPtr(v string) *string { + return &v +} + var casesAuthenticate = []struct { name string vin base.HeaderValue @@ -20,10 +24,7 @@ var casesAuthenticate = []struct { base.HeaderValue{`Basic realm="4419b63f5e51"`}, Authenticate{ Method: AuthBasic, - Realm: func() *string { - v := "4419b63f5e51" - return &v - }(), + Realm: stringPtr("4419b63f5e51"), }, }, { @@ -32,18 +33,9 @@ var casesAuthenticate = []struct { base.HeaderValue{`Digest realm="4419b63f5e51", nonce="8b84a3b789283a8bea8da7fa7d41f08b", stale="FALSE"`}, Authenticate{ Method: AuthDigest, - Realm: func() *string { - v := "4419b63f5e51" - return &v - }(), - Nonce: func() *string { - v := "8b84a3b789283a8bea8da7fa7d41f08b" - return &v - }(), - Stale: func() *string { - v := "FALSE" - return &v - }(), + Realm: stringPtr("4419b63f5e51"), + Nonce: stringPtr("8b84a3b789283a8bea8da7fa7d41f08b"), + Stale: stringPtr("FALSE"), }, }, { @@ -52,18 +44,9 @@ var casesAuthenticate = []struct { base.HeaderValue{`Digest realm="4419b63f5e51", nonce="8b84a3b789283a8bea8da7fa7d41f08b", stale="FALSE"`}, Authenticate{ Method: AuthDigest, - Realm: func() *string { - v := "4419b63f5e51" - return &v - }(), - Nonce: func() *string { - v := "8b84a3b789283a8bea8da7fa7d41f08b" - return &v - }(), - Stale: func() *string { - v := "FALSE" - return &v - }(), + Realm: stringPtr("4419b63f5e51"), + Nonce: stringPtr("8b84a3b789283a8bea8da7fa7d41f08b"), + Stale: stringPtr("FALSE"), }, }, { @@ -72,18 +55,9 @@ var casesAuthenticate = []struct { base.HeaderValue{`Digest realm="4419b63f5e51", nonce="133767111917411116111311118211673010032", stale="FALSE"`}, Authenticate{ Method: AuthDigest, - Realm: func() *string { - v := "4419b63f5e51" - return &v - }(), - Nonce: func() *string { - v := "133767111917411116111311118211673010032" - return &v - }(), - Stale: func() *string { - v := "FALSE" - return &v - }(), + Realm: stringPtr("4419b63f5e51"), + Nonce: stringPtr("133767111917411116111311118211673010032"), + Stale: stringPtr("FALSE"), }, }, { @@ -91,27 +65,12 @@ var casesAuthenticate = []struct { base.HeaderValue{`Digest username="aa", realm="bb", nonce="cc", uri="dd", response="ee"`}, base.HeaderValue{`Digest username="aa", realm="bb", nonce="cc", uri="dd", response="ee"`}, Authenticate{ - Method: AuthDigest, - Username: func() *string { - v := "aa" - return &v - }(), - Realm: func() *string { - v := "bb" - return &v - }(), - Nonce: func() *string { - v := "cc" - return &v - }(), - URI: func() *string { - v := "dd" - return &v - }(), - Response: func() *string { - v := "ee" - return &v - }(), + Method: AuthDigest, + Username: stringPtr("aa"), + Realm: stringPtr("bb"), + Nonce: stringPtr("cc"), + URI: stringPtr("dd"), + Response: stringPtr("ee"), }, }, { @@ -123,27 +82,12 @@ var casesAuthenticate = []struct { `nonce="5d17cd12b9fa8a85ac5ceef0926ea5a6", uri="rtsp://localhost:8554/mystream", ` + `response="c072ae90eb4a27f4cdcb90d62266b2a1"`}, Authenticate{ - Method: AuthDigest, - Username: func() *string { - v := "" - return &v - }(), - Realm: func() *string { - v := "IPCAM" - return &v - }(), - Nonce: func() *string { - v := "5d17cd12b9fa8a85ac5ceef0926ea5a6" - return &v - }(), - URI: func() *string { - v := "rtsp://localhost:8554/mystream" - return &v - }(), - Response: func() *string { - v := "c072ae90eb4a27f4cdcb90d62266b2a1" - return &v - }(), + Method: AuthDigest, + Username: stringPtr(""), + Realm: stringPtr("IPCAM"), + Nonce: stringPtr("5d17cd12b9fa8a85ac5ceef0926ea5a6"), + URI: stringPtr("rtsp://localhost:8554/mystream"), + Response: stringPtr("c072ae90eb4a27f4cdcb90d62266b2a1"), }, }, { @@ -153,27 +97,12 @@ var casesAuthenticate = []struct { base.HeaderValue{`Digest realm="Please log in with a valid username", ` + `nonce="752a62306daf32b401a41004555c7663", opaque="", stale="FALSE", algorithm="MD5"`}, Authenticate{ - Method: AuthDigest, - Realm: func() *string { - v := "Please log in with a valid username" - return &v - }(), - Nonce: func() *string { - v := "752a62306daf32b401a41004555c7663" - return &v - }(), - Opaque: func() *string { - v := "" - return &v - }(), - Stale: func() *string { - v := "FALSE" - return &v - }(), - Algorithm: func() *string { - v := "MD5" - return &v - }(), + Method: AuthDigest, + Realm: stringPtr("Please log in with a valid username"), + Nonce: stringPtr("752a62306daf32b401a41004555c7663"), + Opaque: stringPtr(""), + Stale: stringPtr("FALSE"), + Algorithm: stringPtr("MD5"), }, }, } diff --git a/pkg/headers/authorization_test.go b/pkg/headers/authorization_test.go index e13d792b..71c7806d 100644 --- a/pkg/headers/authorization_test.go +++ b/pkg/headers/authorization_test.go @@ -32,18 +32,9 @@ var casesAuthorization = []struct { Method: AuthDigest, DigestValues: Authenticate{ Method: AuthDigest, - Realm: func() *string { - v := "4419b63f5e51" - return &v - }(), - Nonce: func() *string { - v := "8b84a3b789283a8bea8da7fa7d41f08b" - return &v - }(), - Stale: func() *string { - v := "FALSE" - return &v - }(), + Realm: stringPtr("4419b63f5e51"), + Nonce: stringPtr("8b84a3b789283a8bea8da7fa7d41f08b"), + Stale: stringPtr("FALSE"), }, }, }, diff --git a/pkg/headers/range_test.go b/pkg/headers/range_test.go index bcee4e66..8b633579 100644 --- a/pkg/headers/range_test.go +++ b/pkg/headers/range_test.go @@ -9,6 +9,14 @@ import ( "github.com/bluenviron/gortsplib/v3/pkg/base" ) +func durationPtr(v time.Duration) *time.Duration { + return &v +} + +func timePtr(v time.Time) *time.Time { + return &v +} + var casesRange = []struct { name string vin base.HeaderValue @@ -64,10 +72,7 @@ var casesRange = []struct { Range{ Value: &RangeNPT{ Start: time.Duration(123.45 * float64(time.Second)), - End: func() *time.Duration { - v := 125 * time.Second - return &v - }(), + End: durationPtr(125 * time.Second), }, }, }, @@ -88,10 +93,7 @@ var casesRange = []struct { Range{ Value: &RangeUTC{ Start: time.Date(1996, 11, 8, 14, 23, 0, 0, time.UTC), - End: func() *time.Time { - v := time.Date(1996, 11, 8, 14, 35, 20, 0, time.UTC) - return &v - }(), + End: timePtr(time.Date(1996, 11, 8, 14, 35, 20, 0, time.UTC)), }, }, }, @@ -113,10 +115,7 @@ var casesRange = []struct { Value: &RangeUTC{ Start: time.Date(1996, 2, 13, 14, 32, 5, 0, time.UTC), }, - Time: func() *time.Time { - v := time.Date(1997, 1, 23, 14, 37, 20, 0, time.UTC) - return &v - }(), + Time: timePtr(time.Date(1997, 1, 23, 14, 37, 20, 0, time.UTC)), }, }, } diff --git a/pkg/headers/transport_test.go b/pkg/headers/transport_test.go index 42f44c3d..f31e1c13 100644 --- a/pkg/headers/transport_test.go +++ b/pkg/headers/transport_test.go @@ -9,6 +9,10 @@ import ( "github.com/bluenviron/gortsplib/v3/pkg/base" ) +func ipPtr(v net.IP) *net.IP { + return &v +} + var casesTransport = []struct { name string vin base.HeaderValue @@ -56,12 +60,9 @@ var casesTransport = []struct { v := TransportDeliveryMulticast return &v }(), - Destination: func() *net.IP { - v := net.ParseIP("225.219.201.15") - return &v - }(), - TTL: uintPtr(127), - Ports: &[2]int{7000, 7001}, + Destination: ipPtr(net.ParseIP("225.219.201.15")), + TTL: uintPtr(127), + Ports: &[2]int{7000, 7001}, }, }, { @@ -108,10 +109,7 @@ var casesTransport = []struct { }(), ClientPorts: &[2]int{14186, 14187}, ServerPorts: &[2]int{5000, 5001}, - Source: func() *net.IP { - v := net.ParseIP("127.0.0.1") - return &v - }(), + Source: ipPtr(net.ParseIP("127.0.0.1")), }, }, { @@ -208,10 +206,7 @@ var casesTransport = []struct { v := TransportDeliveryUnicast return &v }(), - Source: func() *net.IP { - v := net.ParseIP("172.16.8.2") - return &v - }(), + Source: ipPtr(net.ParseIP("172.16.8.2")), ClientPorts: &[2]int{14236, 14237}, ServerPorts: &[2]int{56002, 56003}, },