From a9f64f98c2c99c07a9e69a82a1122e3b520790cf Mon Sep 17 00:00:00 2001 From: theresa Date: Thu, 18 Feb 2021 14:39:08 +0100 Subject: [PATCH] Tests: Add tests for internal/config --- internal/config/disable_test.go | 29 ++++++++++++++++++++++++ internal/config/ffmpeg_test.go | 40 +++++++++++++++++++++++++++++++++ internal/config/fs_test.go | 31 +++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 internal/config/disable_test.go create mode 100644 internal/config/ffmpeg_test.go diff --git a/internal/config/disable_test.go b/internal/config/disable_test.go new file mode 100644 index 000000000..a932a067f --- /dev/null +++ b/internal/config/disable_test.go @@ -0,0 +1,29 @@ +package config + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestConfig_DisableBackups(t *testing.T) { + c := NewConfig(CliTestContext()) + assert.False(t, c.DisableBackups()) +} + +func TestConfig_DisableWebDAV(t *testing.T) { + c := NewConfig(CliTestContext()) + assert.False(t, c.DisableWebDAV()) + + c.options.ReadOnly = true + c.options.Demo = true + assert.True(t, c.DisableWebDAV()) +} + +func TestConfig_DisableExifTool(t *testing.T) { + c := NewConfig(CliTestContext()) + assert.False(t, c.DisableExifTool()) + + c.options.ExifToolBin = "XXX" + assert.True(t, c.DisableExifTool()) +} diff --git a/internal/config/ffmpeg_test.go b/internal/config/ffmpeg_test.go new file mode 100644 index 000000000..77c188d8a --- /dev/null +++ b/internal/config/ffmpeg_test.go @@ -0,0 +1,40 @@ +package config + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestConfig_FFmpegEncoder(t *testing.T) { + c := NewConfig(CliTestContext()) + assert.Equal(t, "libx264", c.FFmpegEncoder()) + + c.options.FFmpegEncoder = "testEncoder" + assert.Equal(t, "testEncoder", c.FFmpegEncoder()) +} + +func TestConfig_FFmpegBuffers(t *testing.T) { + c := NewConfig(CliTestContext()) + assert.Equal(t, 8, c.FFmpegBuffers()) + + c.options.FFmpegBuffers = 3300 + assert.Equal(t, 2048, c.FFmpegBuffers()) + + c.options.FFmpegBuffers = 589 + assert.Equal(t, 589, c.FFmpegBuffers()) +} + +func TestConfig_FFmpegBitrate(t *testing.T) { + c := NewConfig(CliTestContext()) + assert.Equal(t, 50, c.FFmpegBitrate()) + + c.options.FFmpegBitrate = 1000 + assert.Equal(t, 960, c.FFmpegBitrate()) + + c.options.FFmpegBitrate = -5 + assert.Equal(t, 50, c.FFmpegBitrate()) + + c.options.FFmpegBitrate = 800 + assert.Equal(t, 800, c.FFmpegBitrate()) +} diff --git a/internal/config/fs_test.go b/internal/config/fs_test.go index 3425f1397..040eabaab 100644 --- a/internal/config/fs_test.go +++ b/internal/config/fs_test.go @@ -41,6 +41,8 @@ func TestConfig_SidecarPath(t *testing.T) { assert.Contains(t, c.SidecarPath(), "testdata/sidecar") c.options.SidecarPath = ".photoprism" assert.Equal(t, ".photoprism", c.SidecarPath()) + c.options.SidecarPath = "" + assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/sidecar", c.SidecarPath()) } func TestConfig_SidecarPathIsAbs(t *testing.T) { @@ -137,3 +139,32 @@ func TestConfig_ImportPath2(t *testing.T) { c.options.ImportPath = "" assert.Equal(t, "", c.ImportPath()) } + +func TestConfig_ConfigPath(t *testing.T) { + c := NewConfig(CliTestContext()) + assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/config", c.ConfigPath()) + c.options.ConfigPath = "" + assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/config", c.ConfigPath()) +} + +func TestConfig_AssetsPath2(t *testing.T) { + c := NewConfig(CliTestContext()) + assert.Equal(t, "/go/src/github.com/photoprism/photoprism/assets", c.AssetsPath()) + c.options.AssetsPath = "" + assert.Equal(t, "", c.AssetsPath()) +} + +func TestConfig_MysqlBin(t *testing.T) { + c := NewConfig(CliTestContext()) + assert.Contains(t, c.MysqlBin(), "mysql") +} + +func TestConfig_MysqldumpBin(t *testing.T) { + c := NewConfig(CliTestContext()) + assert.Contains(t, c.MysqldumpBin(), "mysqldump") +} + +func TestConfig_SqliteBin(t *testing.T) { + c := NewConfig(CliTestContext()) + assert.Contains(t, c.SqliteBin(), "sqlite") +}