From fcf649cdaf72d50331909818d6ae192115d7c6fc Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Mon, 12 Feb 2024 00:20:35 +0100 Subject: [PATCH] tests: make sure that dates with decimal seconds can be parsed correctly (#3007) --- internal/api/api_test.go | 22 +++++++++++----------- internal/playback/server_test.go | 16 ++++++++-------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/internal/api/api_test.go b/internal/api/api_test.go index 33f7fad0c43..610be63bab6 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -512,13 +512,13 @@ func TestRecordingsList(t *testing.T) { err = os.Mkdir(filepath.Join(dir, "mypath2"), 0o755) require.NoError(t, err) - err = os.WriteFile(filepath.Join(dir, "mypath1", "2008-11-07_11-22-00-000000.mp4"), []byte(""), 0o644) + err = os.WriteFile(filepath.Join(dir, "mypath1", "2008-11-07_11-22-00-500000.mp4"), []byte(""), 0o644) require.NoError(t, err) - err = os.WriteFile(filepath.Join(dir, "mypath1", "2009-11-07_11-22-00-000000.mp4"), []byte(""), 0o644) + err = os.WriteFile(filepath.Join(dir, "mypath1", "2009-11-07_11-22-00-900000.mp4"), []byte(""), 0o644) require.NoError(t, err) - err = os.WriteFile(filepath.Join(dir, "mypath2", "2009-11-07_11-22-00-000000.mp4"), []byte(""), 0o644) + err = os.WriteFile(filepath.Join(dir, "mypath2", "2009-11-07_11-22-00-900000.mp4"), []byte(""), 0o644) require.NoError(t, err) hc := &http.Client{Transport: &http.Transport{}} @@ -533,10 +533,10 @@ func TestRecordingsList(t *testing.T) { "name": "mypath1", "segments": []interface{}{ map[string]interface{}{ - "start": time.Date(2008, 11, 0o7, 11, 22, 0, 0, time.Local).Format(time.RFC3339), + "start": time.Date(2008, 11, 0o7, 11, 22, 0, 500000000, time.Local).Format(time.RFC3339Nano), }, map[string]interface{}{ - "start": time.Date(2009, 11, 0o7, 11, 22, 0, 0, time.Local).Format(time.RFC3339), + "start": time.Date(2009, 11, 0o7, 11, 22, 0, 900000000, time.Local).Format(time.RFC3339Nano), }, }, }, @@ -544,7 +544,7 @@ func TestRecordingsList(t *testing.T) { "name": "mypath2", "segments": []interface{}{ map[string]interface{}{ - "start": time.Date(2009, 11, 0o7, 11, 22, 0, 0, time.Local).Format(time.RFC3339), + "start": time.Date(2009, 11, 0o7, 11, 22, 0, 900000000, time.Local).Format(time.RFC3339Nano), }, }, }, @@ -578,7 +578,7 @@ func TestRecordingsGet(t *testing.T) { err = os.WriteFile(filepath.Join(dir, "mypath1", "2008-11-07_11-22-00-000000.mp4"), []byte(""), 0o644) require.NoError(t, err) - err = os.WriteFile(filepath.Join(dir, "mypath1", "2009-11-07_11-22-00-000000.mp4"), []byte(""), 0o644) + err = os.WriteFile(filepath.Join(dir, "mypath1", "2009-11-07_11-22-00-900000.mp4"), []byte(""), 0o644) require.NoError(t, err) hc := &http.Client{Transport: &http.Transport{}} @@ -589,10 +589,10 @@ func TestRecordingsGet(t *testing.T) { "name": "mypath1", "segments": []interface{}{ map[string]interface{}{ - "start": time.Date(2008, 11, 0o7, 11, 22, 0, 0, time.Local).Format(time.RFC3339), + "start": time.Date(2008, 11, 0o7, 11, 22, 0, 0, time.Local).Format(time.RFC3339Nano), }, map[string]interface{}{ - "start": time.Date(2009, 11, 0o7, 11, 22, 0, 0, time.Local).Format(time.RFC3339), + "start": time.Date(2009, 11, 0o7, 11, 22, 0, 900000000, time.Local).Format(time.RFC3339Nano), }, }, }, out) @@ -621,14 +621,14 @@ func TestRecordingsDeleteSegment(t *testing.T) { err = os.Mkdir(filepath.Join(dir, "mypath1"), 0o755) require.NoError(t, err) - err = os.WriteFile(filepath.Join(dir, "mypath1", "2008-11-07_11-22-00-000000.mp4"), []byte(""), 0o644) + err = os.WriteFile(filepath.Join(dir, "mypath1", "2008-11-07_11-22-00-900000.mp4"), []byte(""), 0o644) require.NoError(t, err) hc := &http.Client{Transport: &http.Transport{}} v := url.Values{} v.Set("path", "mypath1") - v.Set("start", time.Date(2008, 11, 0o7, 11, 22, 0, 0, time.Local).Format(time.RFC3339)) + v.Set("start", time.Date(2008, 11, 0o7, 11, 22, 0, 900000000, time.Local).Format(time.RFC3339Nano)) u := &url.URL{ Scheme: "http", diff --git a/internal/playback/server_test.go b/internal/playback/server_test.go index 829e5a6bb9a..a211ab9638e 100644 --- a/internal/playback/server_test.go +++ b/internal/playback/server_test.go @@ -143,8 +143,8 @@ func TestServerGet(t *testing.T) { err = os.Mkdir(filepath.Join(dir, "mypath"), 0o755) require.NoError(t, err) - writeSegment1(t, filepath.Join(dir, "mypath", "2008-11-07_11-22-00-000000.mp4")) - writeSegment2(t, filepath.Join(dir, "mypath", "2008-11-07_11-23-02-000000.mp4")) + writeSegment1(t, filepath.Join(dir, "mypath", "2008-11-07_11-22-00-500000.mp4")) + writeSegment2(t, filepath.Join(dir, "mypath", "2008-11-07_11-23-02-500000.mp4")) s := &Server{ Address: "127.0.0.1:9996", @@ -163,7 +163,7 @@ func TestServerGet(t *testing.T) { v := url.Values{} v.Set("path", "mypath") - v.Set("start", time.Date(2008, 11, 0o7, 11, 23, 1, 0, time.Local).Format(time.RFC3339)) + v.Set("start", time.Date(2008, 11, 0o7, 11, 23, 1, 500000000, time.Local).Format(time.RFC3339Nano)) v.Set("duration", "2") v.Set("format", "fmp4") @@ -236,9 +236,9 @@ func TestServerList(t *testing.T) { err = os.Mkdir(filepath.Join(dir, "mypath"), 0o755) require.NoError(t, err) - writeSegment1(t, filepath.Join(dir, "mypath", "2008-11-07_11-22-00-000000.mp4")) - writeSegment2(t, filepath.Join(dir, "mypath", "2008-11-07_11-23-02-000000.mp4")) - writeSegment2(t, filepath.Join(dir, "mypath", "2009-11-07_11-23-02-000000.mp4")) + writeSegment1(t, filepath.Join(dir, "mypath", "2008-11-07_11-22-00-500000.mp4")) + writeSegment2(t, filepath.Join(dir, "mypath", "2008-11-07_11-23-02-500000.mp4")) + writeSegment2(t, filepath.Join(dir, "mypath", "2009-11-07_11-23-02-500000.mp4")) s := &Server{ Address: "127.0.0.1:9996", @@ -281,11 +281,11 @@ func TestServerList(t *testing.T) { require.Equal(t, []interface{}{ map[string]interface{}{ "duration": float64(64), - "start": time.Date(2008, 11, 0o7, 11, 22, 0, 0, time.Local).Format(time.RFC3339), + "start": time.Date(2008, 11, 0o7, 11, 22, 0, 500000000, time.Local).Format(time.RFC3339Nano), }, map[string]interface{}{ "duration": float64(2), - "start": time.Date(2009, 11, 0o7, 11, 23, 2, 0, time.Local).Format(time.RFC3339), + "start": time.Date(2009, 11, 0o7, 11, 23, 2, 500000000, time.Local).Format(time.RFC3339Nano), }, }, out) }