Skip to content

Commit

Permalink
simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Aug 14, 2023
1 parent 8857e25 commit 98e6e82
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 145 deletions.
9 changes: 5 additions & 4 deletions client_play_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down
135 changes: 32 additions & 103 deletions pkg/headers/authenticate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"),
},
},
{
Expand All @@ -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"),
},
},
{
Expand All @@ -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"),
},
},
{
Expand All @@ -72,46 +55,22 @@ 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"),
},
},
{
"digest response generic",
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"),
},
},
{
Expand All @@ -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"),
},
},
{
Expand All @@ -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"),
},
},
}
Expand Down
15 changes: 3 additions & 12 deletions pkg/headers/authorization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
},
},
Expand Down
23 changes: 11 additions & 12 deletions pkg/headers/range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
},
},
},
Expand All @@ -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)),
},
},
},
Expand All @@ -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)),
},
},
}
Expand Down
23 changes: 9 additions & 14 deletions pkg/headers/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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},
},
},
{
Expand Down Expand Up @@ -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")),
},
},
{
Expand Down Expand Up @@ -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},
},
Expand Down

0 comments on commit 98e6e82

Please sign in to comment.