Tests: Add tests for internal/config

This commit is contained in:
theresa 2021-08-25 13:41:51 +02:00
parent 06835a3c5c
commit 3c24481750
2 changed files with 158 additions and 4 deletions

View file

@ -130,22 +130,146 @@ func TestConfig_CreateDirectories2(t *testing.T) {
c.options.AssetsPath = ""
err := c.CreateDirectories()
if err == nil {
t.Fatal("error expected")
}
assert.Contains(t, err.Error(), "assets path not found")
c.options.AssetsPath = "/-*&^%$#@!`~"
err2 := c.CreateDirectories()
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
})
t.Run("asset path not found", func(t *testing.T) {
t.Run("storage path error", func(t *testing.T) {
testConfigMutex.Lock()
defer testConfigMutex.Unlock()
c := &Config{
options: NewTestOptions(),
token: rnd.Token(8),
}
c.options.StoragePath = "/-*&^%$#@!`~"
err2 := c.CreateDirectories()
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
})
t.Run("originals path not found", func(t *testing.T) {
testConfigMutex.Lock()
defer testConfigMutex.Unlock()
c := &Config{
options: NewTestOptions(),
token: rnd.Token(8),
}
t.Log(c.options.OriginalsPath)
c.options.OriginalsPath = ""
t.Log(c.options.OriginalsPath)
err := c.CreateDirectories()
t.Log(err)
if err == nil {
t.Fatal("error expected")
}
assert.Contains(t, err.Error(), "originals path not found")
c.options.OriginalsPath = "/-*&^%$#@!`~"
err2 := c.CreateDirectories()
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
})
t.Run("import path not found", func(t *testing.T) {
testConfigMutex.Lock()
defer testConfigMutex.Unlock()
c := &Config{
options: NewTestOptions(),
token: rnd.Token(8),
}
c.options.ImportPath = ""
err := c.CreateDirectories()
if err == nil {
t.Fatal("error expected")
}
assert.Contains(t, err.Error(), "import path not found")
c.options.ImportPath = "/-*&^%$#@!`~"
err2 := c.CreateDirectories()
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
})
t.Run("sidecar path error", func(t *testing.T) {
testConfigMutex.Lock()
defer testConfigMutex.Unlock()
c := &Config{
options: NewTestOptions(),
token: rnd.Token(8),
}
c.options.SidecarPath = "/-*&^%$#@!`~"
err2 := c.CreateDirectories()
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
})
t.Run("cache path error", func(t *testing.T) {
testConfigMutex.Lock()
defer testConfigMutex.Unlock()
c := &Config{
options: NewTestOptions(),
token: rnd.Token(8),
}
c.options.CachePath = "/-*&^%$#@!`~"
err2 := c.CreateDirectories()
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
})
t.Run("config path error", func(t *testing.T) {
testConfigMutex.Lock()
defer testConfigMutex.Unlock()
c := &Config{
options: NewTestOptions(),
token: rnd.Token(8),
}
c.options.ConfigPath = "/-*&^%$#@!`~"
err2 := c.CreateDirectories()
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
})
t.Run("temp path error", func(t *testing.T) {
testConfigMutex.Lock()
defer testConfigMutex.Unlock()
c := &Config{
options: NewTestOptions(),
token: rnd.Token(8),
}
c.options.TempPath = "/-*&^%$#@!`~"
err2 := c.CreateDirectories()
if err2 == nil {
t.Fatal("error expected")
}
assert.Contains(t, err2.Error(), "please check configuration and permissions")
})
}

View file

@ -12,6 +12,14 @@ func TestConfig_RawtherapeeBin(t *testing.T) {
assert.Equal(t, "/usr/bin/rawtherapee-cli", c.RawtherapeeBin())
}
func TestConfig_RawtherapeeEnabled(t *testing.T) {
c := NewConfig(CliTestContext())
assert.True(t, c.RawtherapeeEnabled())
c.options.DisableRawtherapee = true
assert.False(t, c.RawtherapeeEnabled())
}
func TestConfig_DarktableBin(t *testing.T) {
c := NewConfig(CliTestContext())
@ -24,6 +32,14 @@ func TestConfig_DarktablePresets(t *testing.T) {
assert.False(t, c.RawPresets())
}
func TestConfig_DarktableEnabled(t *testing.T) {
c := NewConfig(CliTestContext())
assert.True(t, c.DarktableEnabled())
c.options.DisableDarktable = true
assert.False(t, c.DarktableEnabled())
}
func TestConfig_SipsBin(t *testing.T) {
c := NewConfig(CliTestContext())
@ -31,9 +47,23 @@ func TestConfig_SipsBin(t *testing.T) {
assert.Equal(t, "", bin)
}
func TestConfig_SipsEnabled(t *testing.T) {
c := NewConfig(CliTestContext())
c.options.DisableSips = true
assert.False(t, c.SipsEnabled())
}
func TestConfig_HeifConvertBin(t *testing.T) {
c := NewConfig(CliTestContext())
bin := c.HeifConvertBin()
assert.Contains(t, bin, "/bin/heif-convert")
}
func TestConfig_HeifConvertEnabled(t *testing.T) {
c := NewConfig(CliTestContext())
assert.True(t, c.HeifConvertEnabled())
c.options.DisableHeifConvert = true
assert.False(t, c.HeifConvertEnabled())
}