From 4727f769d29e8419104fec506b6a2e3a112be245 Mon Sep 17 00:00:00 2001 From: graciousgrey Date: Thu, 20 Jul 2023 19:17:45 +0200 Subject: [PATCH] Tests: Add unit tests --- internal/commands/show_config_options_test.go | 3 +- internal/commands/show_config_yaml_test.go | 3 +- internal/commands/show_thumb_sizes_test.go | 3 +- internal/commands/show_video_sizes_test.go | 3 +- internal/ffmpeg/config_test.go | 29 +++++++++++++++++++ internal/ffmpeg/preview_test.go | 1 + 6 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 internal/ffmpeg/config_test.go diff --git a/internal/commands/show_config_options_test.go b/internal/commands/show_config_options_test.go index 4387bd78a..fe4bd602f 100644 --- a/internal/commands/show_config_options_test.go +++ b/internal/commands/show_config_options_test.go @@ -1,10 +1,11 @@ package commands import ( + "testing" + "github.com/photoprism/photoprism/internal/config" "github.com/photoprism/photoprism/pkg/capture" "github.com/stretchr/testify/assert" - "testing" ) func TestShowConfigOptionsCommand(t *testing.T) { diff --git a/internal/commands/show_config_yaml_test.go b/internal/commands/show_config_yaml_test.go index 14d97819a..a233856e1 100644 --- a/internal/commands/show_config_yaml_test.go +++ b/internal/commands/show_config_yaml_test.go @@ -1,10 +1,11 @@ package commands import ( + "testing" + "github.com/photoprism/photoprism/internal/config" "github.com/photoprism/photoprism/pkg/capture" "github.com/stretchr/testify/assert" - "testing" ) func TestShowConfigYamlCommand(t *testing.T) { diff --git a/internal/commands/show_thumb_sizes_test.go b/internal/commands/show_thumb_sizes_test.go index 95a95bd07..1576abe78 100644 --- a/internal/commands/show_thumb_sizes_test.go +++ b/internal/commands/show_thumb_sizes_test.go @@ -1,10 +1,11 @@ package commands import ( + "testing" + "github.com/photoprism/photoprism/internal/config" "github.com/photoprism/photoprism/pkg/capture" "github.com/stretchr/testify/assert" - "testing" ) func TestShowThumbSizesCommand(t *testing.T) { diff --git a/internal/commands/show_video_sizes_test.go b/internal/commands/show_video_sizes_test.go index b47b43458..dbaf0c552 100644 --- a/internal/commands/show_video_sizes_test.go +++ b/internal/commands/show_video_sizes_test.go @@ -1,10 +1,11 @@ package commands import ( + "testing" + "github.com/photoprism/photoprism/internal/config" "github.com/photoprism/photoprism/pkg/capture" "github.com/stretchr/testify/assert" - "testing" ) func TestShowVideoSizesCommand(t *testing.T) { diff --git a/internal/ffmpeg/config_test.go b/internal/ffmpeg/config_test.go new file mode 100644 index 000000000..c82f706f3 --- /dev/null +++ b/internal/ffmpeg/config_test.go @@ -0,0 +1,29 @@ +package ffmpeg + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestOptions_VideoFilter(t *testing.T) { + Options := &Options{ + Bin: "", + Encoder: "intel", + Size: 1500, + Bitrate: "50", + MapVideo: "", + MapAudio: "", + } + + t.Run("rgb32", func(t *testing.T) { + r := Options.VideoFilter("rgb32") + assert.Contains(t, r, "format=rgb32") + assert.Contains(t, r, "min(1500, iw)") + }) + t.Run("empty format", func(t *testing.T) { + r := Options.VideoFilter("") + assert.NotContains(t, r, "format") + assert.Contains(t, r, "min(1500, iw)") + }) +} diff --git a/internal/ffmpeg/preview_test.go b/internal/ffmpeg/preview_test.go index ace1fe17c..b8c013777 100644 --- a/internal/ffmpeg/preview_test.go +++ b/internal/ffmpeg/preview_test.go @@ -11,6 +11,7 @@ func TestPreviewTimeOffset(t *testing.T) { assert.Equal(t, "00:00:00.001", PreviewTimeOffset(time.Second)) assert.Equal(t, "00:00:03.000", PreviewTimeOffset(time.Minute)) assert.Equal(t, "00:00:09.000", PreviewTimeOffset(3*time.Minute)) + assert.Equal(t, "00:00:30.000", PreviewTimeOffset(5*time.Minute)) assert.Equal(t, "00:01:00.000", PreviewTimeOffset(15*time.Minute)) assert.Equal(t, "00:01:00.000", PreviewTimeOffset(30*time.Minute)) assert.Equal(t, "00:01:00.000", PreviewTimeOffset(time.Hour))