Tests: Add tests for internal/config

This commit is contained in:
theresa 2021-02-18 14:39:08 +01:00
parent 67594db4a2
commit a9f64f98c2
3 changed files with 100 additions and 0 deletions

View file

@ -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())
}

View file

@ -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())
}

View file

@ -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")
}