diff --git a/internal/certloader/certloader_test.go b/internal/certloader/certloader_test.go index f85864bc..9dc4a4a1 100644 --- a/internal/certloader/certloader_test.go +++ b/internal/certloader/certloader_test.go @@ -1,4 +1,4 @@ -package certloader +package certloader_test import ( "crypto/tls" @@ -6,6 +6,7 @@ import ( "testing" "time" + "github.com/bluenviron/mediamtx/internal/certloader" "github.com/bluenviron/mediamtx/internal/test" "github.com/stretchr/testify/require" ) @@ -17,7 +18,7 @@ func TestCertReload(t *testing.T) { serverCertPath := test.CreateTempFile(t, test.TLSCertPub) serverKeyPath := test.CreateTempFile(t, test.TLSCertKey) - loader := &CertLoader{ + loader := &certloader.CertLoader{ CertPath: serverCertPath, KeyPath: serverKeyPath, Parent: test.NilLogger, diff --git a/internal/confwatcher/confwatcher_test.go b/internal/confwatcher/confwatcher_test.go index 3f5dc8c8..48010086 100644 --- a/internal/confwatcher/confwatcher_test.go +++ b/internal/confwatcher/confwatcher_test.go @@ -1,16 +1,17 @@ -package confwatcher +package confwatcher_test import ( "os" "testing" "time" + "github.com/bluenviron/mediamtx/internal/confwatcher" "github.com/bluenviron/mediamtx/internal/test" "github.com/stretchr/testify/require" ) func TestNoFile(t *testing.T) { - w := &ConfWatcher{FilePath: "/nonexistent"} + w := &confwatcher.ConfWatcher{FilePath: "/nonexistent"} err := w.Initialize() require.Error(t, err) } @@ -18,7 +19,7 @@ func TestNoFile(t *testing.T) { func TestWrite(t *testing.T) { fpath := test.CreateTempFile(t, []byte("{}")) - w := &ConfWatcher{FilePath: fpath} + w := &confwatcher.ConfWatcher{FilePath: fpath} err := w.Initialize() require.NoError(t, err) defer w.Close() @@ -44,7 +45,7 @@ func TestWrite(t *testing.T) { func TestWriteMultipleTimes(t *testing.T) { fpath := test.CreateTempFile(t, []byte("{}")) - w := &ConfWatcher{FilePath: fpath} + w := &confwatcher.ConfWatcher{FilePath: fpath} err := w.Initialize() require.NoError(t, err) defer w.Close() @@ -87,7 +88,7 @@ func TestWriteMultipleTimes(t *testing.T) { func TestDeleteCreate(t *testing.T) { fpath := test.CreateTempFile(t, []byte("{}")) - w := &ConfWatcher{FilePath: fpath} + w := &confwatcher.ConfWatcher{FilePath: fpath} err := w.Initialize() require.NoError(t, err) defer w.Close() @@ -120,7 +121,7 @@ func TestSymlinkDeleteCreate(t *testing.T) { err := os.Symlink(fpath, fpath+"-sym") require.NoError(t, err) - w := &ConfWatcher{FilePath: fpath + "-sym"} + w := &confwatcher.ConfWatcher{FilePath: fpath + "-sym"} err = w.Initialize() require.NoError(t, err) defer w.Close() diff --git a/internal/pprof/pprof_test.go b/internal/pprof/pprof_test.go index cb9850ba..a272c533 100644 --- a/internal/pprof/pprof_test.go +++ b/internal/pprof/pprof_test.go @@ -1,4 +1,4 @@ -package pprof //nolint:revive +package pprof_test //nolint:revive import ( "fmt" @@ -9,12 +9,13 @@ import ( "github.com/bluenviron/mediamtx/internal/auth" "github.com/bluenviron/mediamtx/internal/conf" + "github.com/bluenviron/mediamtx/internal/pprof" "github.com/bluenviron/mediamtx/internal/test" "github.com/stretchr/testify/require" ) func TestPreflightRequest(t *testing.T) { - s := &PPROF{ + s := &pprof.PPROF{ Address: "127.0.0.1:9999", AllowOrigins: []string{"*"}, ReadTimeout: conf.Duration(10 * time.Second), @@ -52,7 +53,7 @@ func TestPreflightRequest(t *testing.T) { func TestPprof(t *testing.T) { checked := false - s := &PPROF{ + s := &pprof.PPROF{ Address: "127.0.0.1:9999", AllowOrigins: []string{"*"}, ReadTimeout: conf.Duration(10 * time.Second), @@ -93,7 +94,7 @@ func TestPprof(t *testing.T) { } func TestAuthError(t *testing.T) { - s := &PPROF{ + s := &pprof.PPROF{ Address: "127.0.0.1:9999", AllowOrigins: []string{"*"}, ReadTimeout: conf.Duration(10 * time.Second), diff --git a/internal/protocols/httpp/server_test.go b/internal/protocols/httpp/server_test.go index 3c71583e..936226bf 100644 --- a/internal/protocols/httpp/server_test.go +++ b/internal/protocols/httpp/server_test.go @@ -1,4 +1,4 @@ -package httpp +package httpp_test import ( "net" @@ -10,11 +10,12 @@ import ( "github.com/stretchr/testify/require" + "github.com/bluenviron/mediamtx/internal/protocols/httpp" "github.com/bluenviron/mediamtx/internal/test" ) func TestUnixSocket(t *testing.T) { - s := &Server{ + s := &httpp.Server{ Address: "unix://http.sock", ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second, diff --git a/internal/protocols/tls/make_config_test.go b/internal/protocols/tls/make_config_test.go index facc5752..341f37dd 100644 --- a/internal/protocols/tls/make_config_test.go +++ b/internal/protocols/tls/make_config_test.go @@ -1,4 +1,4 @@ -package tls //nolint:revive +package tls_test //nolint:revive import ( "crypto/tls" @@ -6,6 +6,8 @@ import ( "testing" "github.com/stretchr/testify/require" + + mtls "github.com/bluenviron/mediamtx/internal/protocols/tls" ) var testTLSCertPub = []byte(`-----BEGIN CERTIFICATE----- @@ -87,7 +89,7 @@ func TestMakeConfigFingerprint(t *testing.T) { require.NoError(t, err2) }() - conf := MakeConfig("33949e05fffb5ff3e8aa16f8213a6251b4d9363804ba53233c4da9a46d6f2739") + conf := mtls.MakeConfig("33949e05fffb5ff3e8aa16f8213a6251b4d9363804ba53233c4da9a46d6f2739") conn, err := tls.Dial("tcp", "localhost:8556", conf) require.NoError(t, err) diff --git a/internal/protocols/whip/link_header_test.go b/internal/protocols/whip/link_header_test.go index 0f797a43..90dd5e98 100644 --- a/internal/protocols/whip/link_header_test.go +++ b/internal/protocols/whip/link_header_test.go @@ -1,10 +1,12 @@ -package whip +package whip_test import ( "testing" "github.com/pion/webrtc/v4" "github.com/stretchr/testify/require" + + "github.com/bluenviron/mediamtx/internal/protocols/whip" ) var linkHeaderCases = []struct { @@ -49,7 +51,7 @@ var linkHeaderCases = []struct { func TestLinkHeaderUnmarshal(t *testing.T) { for _, ca := range linkHeaderCases { t.Run(ca.name, func(t *testing.T) { - dec, err := LinkHeaderUnmarshal(ca.enc) + dec, err := whip.LinkHeaderUnmarshal(ca.enc) require.NoError(t, err) require.Equal(t, ca.dec, dec) }) @@ -59,7 +61,7 @@ func TestLinkHeaderUnmarshal(t *testing.T) { func TestLinkHeaderMarshal(t *testing.T) { for _, ca := range linkHeaderCases { t.Run(ca.name, func(t *testing.T) { - enc := LinkHeaderMarshal(ca.dec) + enc := whip.LinkHeaderMarshal(ca.dec) require.Equal(t, ca.enc, enc) }) } @@ -86,7 +88,7 @@ func TestLinkHeaderUnmarshalInvalid(t *testing.T) { }, } { t.Run(ca.name, func(t *testing.T) { - _, err := LinkHeaderUnmarshal(ca.enc) + _, err := whip.LinkHeaderUnmarshal(ca.enc) require.Error(t, err) }) } diff --git a/internal/recordstore/path_test.go b/internal/recordstore/path_test.go index 661aceb1..31e42ecd 100644 --- a/internal/recordstore/path_test.go +++ b/internal/recordstore/path_test.go @@ -1,22 +1,24 @@ -package recordstore +package recordstore_test import ( "testing" "time" "github.com/stretchr/testify/require" + + "github.com/bluenviron/mediamtx/internal/recordstore" ) var pathCases = []struct { name string format string - dec Path + dec recordstore.Path enc string }{ { "standard", "%path/%Y-%m-%d_%H-%M-%S-%f.mp4", - Path{ + recordstore.Path{ Start: time.Date(2008, 11, 7, 11, 22, 4, 123456000, time.Local), Path: "mypath", }, @@ -25,7 +27,7 @@ var pathCases = []struct { { "unix seconds", "%path/%s.mp4", - Path{ + recordstore.Path{ Start: time.Date(2021, 12, 2, 12, 15, 23, 0, time.UTC).Local(), Path: "mypath", }, @@ -34,7 +36,7 @@ var pathCases = []struct { { "unix microseconds", "%path/%s.%f.mp4", - Path{ + recordstore.Path{ Start: time.Date(2021, 12, 2, 12, 15, 23, 567324000, time.UTC).Local(), Path: "mypath", }, @@ -43,7 +45,7 @@ var pathCases = []struct { { "timezone utc", "%path/%Y-%m-%d_%H-%M-%S-%f_%z.mp4", - Path{ + recordstore.Path{ Start: time.Date(2021, 12, 2, 12, 15, 23, 567324000, time.UTC), Path: "mypath", }, @@ -52,7 +54,7 @@ var pathCases = []struct { { "timezone plus", "%path/%Y-%m-%d_%H-%M-%S-%f_%z.mp4", - Path{ + recordstore.Path{ Start: time.Date(2021, 12, 2, 12, 15, 23, 567324000, time.FixedZone("myzone", 7200)), Path: "mypath", }, @@ -61,7 +63,7 @@ var pathCases = []struct { { "timezone minus", "%path/%Y-%m-%d_%H-%M-%S-%f_%z.mp4", - Path{ + recordstore.Path{ Start: time.Date(2021, 12, 2, 12, 15, 23, 567324000, time.FixedZone("myzone", -7200)), Path: "mypath", }, @@ -70,7 +72,7 @@ var pathCases = []struct { { "timezone plus fractional hour", "%path/%Y-%m-%d_%H-%M-%S-%f_%z.mp4", - Path{ + recordstore.Path{ Start: time.Date(2021, 12, 2, 12, 15, 23, 567324000, time.FixedZone("myzone", 19800)), Path: "mypath", }, @@ -79,7 +81,7 @@ var pathCases = []struct { { "timezone plus fractional hour 45", "%path/%Y-%m-%d_%H-%M-%S-%f_%z.mp4", - Path{ + recordstore.Path{ Start: time.Date(2021, 12, 2, 12, 15, 23, 567324000, time.FixedZone("myzone", 20700)), Path: "mypath", }, @@ -88,7 +90,7 @@ var pathCases = []struct { { "timezone minus fractional hour", "%path/%Y-%m-%d_%H-%M-%S-%f_%z.mp4", - Path{ + recordstore.Path{ Start: time.Date(2021, 12, 2, 12, 15, 23, 567324000, time.FixedZone("myzone", -12600)), Path: "mypath", }, @@ -99,7 +101,7 @@ var pathCases = []struct { func TestPathDecode(t *testing.T) { for _, ca := range pathCases { t.Run(ca.name, func(t *testing.T) { - var dec Path + var dec recordstore.Path ok := dec.Decode(ca.format, ca.enc) require.Equal(t, true, ok) require.Equal(t, ca.dec, dec)