2023-12-02 14:15:17 +00:00
|
|
|
package record
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2023-12-02 14:35:21 +00:00
|
|
|
var pathCases = []struct {
|
2023-12-02 14:15:17 +00:00
|
|
|
name string
|
|
|
|
format string
|
2024-01-23 19:52:05 +00:00
|
|
|
dec Path
|
2023-12-02 14:15:17 +00:00
|
|
|
enc string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
"standard",
|
|
|
|
"%path/%Y-%m-%d_%H-%M-%S-%f.mp4",
|
2024-02-04 22:51:51 +00:00
|
|
|
Path{
|
|
|
|
Start: time.Date(2008, 11, 0o7, 11, 22, 4, 123456000, time.Local),
|
|
|
|
Path: "mypath",
|
|
|
|
},
|
|
|
|
"mypath/2008-11-07_11-22-04-123456.mp4",
|
2023-12-02 14:15:17 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"unix seconds",
|
|
|
|
"%path/%s.mp4",
|
2024-02-04 22:51:51 +00:00
|
|
|
Path{
|
|
|
|
Start: time.Date(2021, 12, 2, 12, 15, 23, 0, time.UTC).Local(),
|
|
|
|
Path: "mypath",
|
|
|
|
},
|
|
|
|
"mypath/1638447323.mp4",
|
2023-12-02 14:15:17 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-12-02 14:35:21 +00:00
|
|
|
func TestPathDecode(t *testing.T) {
|
|
|
|
for _, ca := range pathCases {
|
2023-12-02 14:15:17 +00:00
|
|
|
t.Run(ca.name, func(t *testing.T) {
|
2024-01-23 19:52:05 +00:00
|
|
|
var dec Path
|
|
|
|
ok := dec.Decode(ca.format, ca.enc)
|
2023-12-02 14:15:17 +00:00
|
|
|
require.Equal(t, true, ok)
|
|
|
|
require.Equal(t, ca.dec, dec)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-02 14:35:21 +00:00
|
|
|
func TestPathEncode(t *testing.T) {
|
|
|
|
for _, ca := range pathCases {
|
2023-12-02 14:15:17 +00:00
|
|
|
t.Run(ca.name, func(t *testing.T) {
|
2024-01-23 19:52:05 +00:00
|
|
|
require.Equal(t, ca.enc, ca.dec.Encode(ca.format))
|
2023-12-02 14:15:17 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|