Backend: Add unit tests for internal/config
This commit is contained in:
parent
9f88bacb13
commit
6504c7ae74
4 changed files with 105 additions and 0 deletions
|
@ -40,3 +40,12 @@ func TestParams_SetValuesFromFile(t *testing.T) {
|
|||
assert.NotEmpty(t, c.DatabaseDsn)
|
||||
assert.Equal(t, 81, c.HttpServerPort)
|
||||
}
|
||||
|
||||
func TestParams_ExpandFilenames(t *testing.T) {
|
||||
p := Params{TempPath: "tmp", ImportPath: "import"}
|
||||
assert.Equal(t, "tmp", p.TempPath)
|
||||
assert.Equal(t, "import", p.ImportPath)
|
||||
p.expandFilenames()
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/internal/config/tmp", p.TempPath)
|
||||
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/internal/config/import", p.ImportPath)
|
||||
}
|
||||
|
|
58
internal/config/resample_test.go
Normal file
58
internal/config/resample_test.go
Normal file
|
@ -0,0 +1,58 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"github.com/photoprism/photoprism/internal/thumb"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConfig_ConvertSize(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, int(720), c.ConvertSize())
|
||||
c.params.ConvertSize = 31000
|
||||
assert.Equal(t, int(30000), c.ConvertSize())
|
||||
c.params.ConvertSize = 800
|
||||
assert.Equal(t, int(800), c.ConvertSize())
|
||||
}
|
||||
|
||||
func TestConfig_JpegQuality(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, int(25), c.JpegQuality())
|
||||
c.params.JpegQuality = 110
|
||||
assert.Equal(t, int(100), c.JpegQuality())
|
||||
c.params.JpegQuality = 98
|
||||
assert.Equal(t, int(98), c.JpegQuality())
|
||||
}
|
||||
|
||||
func TestConfig_ThumbFilter(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, thumb.ResampleFilter("cubic"), c.ThumbFilter())
|
||||
c.params.ThumbFilter = "blackman"
|
||||
assert.Equal(t, thumb.ResampleFilter("blackman"), c.ThumbFilter())
|
||||
c.params.ThumbFilter = "lanczos"
|
||||
assert.Equal(t, thumb.ResampleFilter("lanczos"), c.ThumbFilter())
|
||||
c.params.ThumbFilter = "linear"
|
||||
assert.Equal(t, thumb.ResampleFilter("linear"), c.ThumbFilter())
|
||||
}
|
||||
|
||||
func TestConfig_ThumbSizeUncached(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.False(t, c.ThumbUncached())
|
||||
}
|
||||
|
||||
func TestConfig_ThumbSize(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, int(720), c.ThumbSize())
|
||||
c.params.ThumbSize = 7681
|
||||
assert.Equal(t, int(7680), c.ThumbSize())
|
||||
}
|
||||
|
||||
func TestConfig_ThumbSizeUncached2(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, int(720), c.ThumbSizeUncached())
|
||||
c.params.ThumbSizeUncached = 7681
|
||||
assert.Equal(t, int(7680), c.ThumbSizeUncached())
|
||||
c.params.ThumbSizeUncached = 800
|
||||
c.params.ThumbSize = 900
|
||||
assert.Equal(t, int(900), c.ThumbSize())
|
||||
}
|
34
internal/config/server_test.go
Normal file
34
internal/config/server_test.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestConfig_HttpServerHost2(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, "0.0.0.0", c.HttpServerHost())
|
||||
c.params.HttpServerHost = "test"
|
||||
assert.Equal(t, "test", c.HttpServerHost())
|
||||
}
|
||||
|
||||
func TestConfig_HttpServerPort2(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, int(2342), c.HttpServerPort())
|
||||
c.params.HttpServerPort = int(1234)
|
||||
assert.Equal(t, int(1234), c.HttpServerPort())
|
||||
}
|
||||
|
||||
func TestConfig_HttpServerMode2(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, "debug", c.HttpServerMode())
|
||||
c.params.Debug = false
|
||||
assert.Equal(t, "release", c.HttpServerMode())
|
||||
}
|
||||
|
||||
func TestConfig_TemplateName(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, "index.tmpl", c.TemplateName())
|
||||
c.settings.Templates.Default = "rainbow.tmpl"
|
||||
assert.Equal(t, "rainbow.tmpl", c.TemplateName())
|
||||
}
|
|
@ -9,6 +9,10 @@ import (
|
|||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func TestConfig_TestdataPath2(t *testing.T) {
|
||||
assert.Equal(t, "/xxx/testdata", testDataPath("/xxx"))
|
||||
}
|
||||
|
||||
func TestTestCliContext(t *testing.T) {
|
||||
result := CliTestContext()
|
||||
|
||||
|
|
Loading…
Reference in a new issue