Backend: Add unit tests for internal/config
This commit is contained in:
parent
faba5c3195
commit
119784ef2c
4 changed files with 46 additions and 1 deletions
|
@ -22,3 +22,12 @@ func TestConfig_GuestConfig(t *testing.T) {
|
|||
assert.IsType(t, ClientConfig{}, result)
|
||||
assert.Equal(t, true, result.Public)
|
||||
}
|
||||
|
||||
func TestConfig_Flags(t *testing.T) {
|
||||
config := NewTestConfig()
|
||||
config.params.Experimental = true
|
||||
config.params.ReadOnly = true
|
||||
|
||||
result := config.Flags()
|
||||
assert.Equal(t, []string{"public", "debug", "experimental", "readonly", "settings"}, result)
|
||||
}
|
||||
|
|
|
@ -337,9 +337,38 @@ func TestConfig_WakeupInterval(t *testing.T) {
|
|||
func TestConfig_GeoCodingApi(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, "", c.GeoCodingApi())
|
||||
c.params.GeoCodingApi = "places"
|
||||
assert.Equal(t, "places", c.GeoCodingApi())
|
||||
c.params.GeoCodingApi = "osm"
|
||||
assert.Equal(t, "osm", c.GeoCodingApi())
|
||||
}
|
||||
|
||||
func TestConfig_OriginalsLimit(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, int64(-1), c.OriginalsLimit())
|
||||
c.params.OriginalsLimit = 800
|
||||
assert.Equal(t, int64(838860800), c.OriginalsLimit())
|
||||
}
|
||||
|
||||
func TestConfig_SiteUrl(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, "http://localhost:2342/", c.SiteUrl())
|
||||
c.params.SiteUrl = "http://superhost:2342/"
|
||||
assert.Equal(t, "http://superhost:2342/", c.SiteUrl())
|
||||
}
|
||||
|
||||
func TestConfig_SitePreview(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, "http://localhost:2342/static/img/preview.jpg", c.SitePreview())
|
||||
c.params.SitePreview = "http://preview.jpg"
|
||||
assert.Equal(t, "http://preview.jpg", c.SitePreview())
|
||||
c.params.SitePreview = "preview123.jpg"
|
||||
assert.Equal(t, "http://localhost:2342/preview123.jpg", c.SitePreview())
|
||||
}
|
||||
|
||||
func TestConfig_SiteTitle(t *testing.T) {
|
||||
c := NewTestConfig()
|
||||
assert.Equal(t, "PhotoPrism", c.SiteTitle())
|
||||
c.params.SiteTitle = "Cats"
|
||||
assert.Equal(t, "Cats", c.SiteTitle())
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ func TestConfig_ThumbFilter(t *testing.T) {
|
|||
assert.Equal(t, thumb.ResampleFilter("lanczos"), c.ThumbFilter())
|
||||
c.params.ThumbFilter = "linear"
|
||||
assert.Equal(t, thumb.ResampleFilter("linear"), c.ThumbFilter())
|
||||
c.params.ThumbFilter = "cubic"
|
||||
assert.Equal(t, thumb.ResampleFilter("cubic"), c.ThumbFilter())
|
||||
}
|
||||
|
||||
func TestConfig_ThumbSizeUncached(t *testing.T) {
|
||||
|
@ -54,5 +56,5 @@ func TestConfig_ThumbSizeUncached2(t *testing.T) {
|
|||
assert.Equal(t, int(7680), c.ThumbSizeUncached())
|
||||
c.params.ThumbSizeUncached = 800
|
||||
c.params.ThumbSize = 900
|
||||
assert.Equal(t, int(900), c.ThumbSize())
|
||||
assert.Equal(t, int(900), c.ThumbSizeUncached())
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ func TestConfig_HttpServerMode2(t *testing.T) {
|
|||
assert.Equal(t, "debug", c.HttpServerMode())
|
||||
c.params.Debug = false
|
||||
assert.Equal(t, "release", c.HttpServerMode())
|
||||
c.params.HttpServerMode = "test"
|
||||
assert.Equal(t, "test", c.HttpServerMode())
|
||||
}
|
||||
|
||||
func TestConfig_TemplateName(t *testing.T) {
|
||||
|
@ -31,4 +33,7 @@ func TestConfig_TemplateName(t *testing.T) {
|
|||
assert.Equal(t, "index.tmpl", c.TemplateName())
|
||||
c.settings.Templates.Default = "rainbow.tmpl"
|
||||
assert.Equal(t, "rainbow.tmpl", c.TemplateName())
|
||||
c.settings.Templates.Default = "xxx"
|
||||
assert.Equal(t, "index.tmpl", c.TemplateName())
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue