golanggohlsrtmpwebrtcmedia-serverobs-studiortcprtmp-proxyrtmp-serverrtprtsprtsp-proxyrtsp-relayrtsp-serversrtstreamingwebrtc-proxy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
51 lines
1.3 KiB
package record |
|
|
|
import ( |
|
"os" |
|
"path/filepath" |
|
"testing" |
|
"time" |
|
|
|
"github.com/bluenviron/mediamtx/internal/conf" |
|
"github.com/stretchr/testify/require" |
|
) |
|
|
|
func TestCleaner(t *testing.T) { |
|
timeNow = func() time.Time { |
|
return time.Date(2009, 0o5, 20, 22, 15, 25, 427000, time.Local) |
|
} |
|
|
|
dir, err := os.MkdirTemp("", "mediamtx-cleaner") |
|
require.NoError(t, err) |
|
defer os.RemoveAll(dir) |
|
|
|
const specialChars = "_-+*?^$()[]{}|" |
|
|
|
err = os.Mkdir(filepath.Join(dir, specialChars+"_mypath"), 0o755) |
|
require.NoError(t, err) |
|
|
|
err = os.WriteFile(filepath.Join(dir, specialChars+"_mypath", "2008-05-20_22-15-25-000125.mp4"), []byte{1}, 0o644) |
|
require.NoError(t, err) |
|
|
|
err = os.WriteFile(filepath.Join(dir, specialChars+"_mypath", "2009-05-20_22-15-25-000427.mp4"), []byte{1}, 0o644) |
|
require.NoError(t, err) |
|
|
|
c := &Cleaner{ |
|
Entries: []CleanerEntry{{ |
|
Path: filepath.Join(dir, specialChars+"_%path/%Y-%m-%d_%H-%M-%S-%f"), |
|
Format: conf.RecordFormatFMP4, |
|
DeleteAfter: 10 * time.Second, |
|
}}, |
|
Parent: nilLogger{}, |
|
} |
|
c.Initialize() |
|
defer c.Close() |
|
|
|
time.Sleep(500 * time.Millisecond) |
|
|
|
_, err = os.Stat(filepath.Join(dir, specialChars+"_mypath", "2008-05-20_22-15-25-000125.mp4")) |
|
require.Error(t, err) |
|
|
|
_, err = os.Stat(filepath.Join(dir, specialChars+"_mypath", "2009-05-20_22-15-25-000427.mp4")) |
|
require.NoError(t, err) |
|
}
|
|
|