From 3c2448175018f506740ea16c34b763ac44c2015d Mon Sep 17 00:00:00 2001 From: theresa Date: Wed, 25 Aug 2021 13:41:51 +0200 Subject: [PATCH] Tests: Add tests for internal/config --- internal/config/fs_test.go | 132 ++++++++++++++++++++++++++++++++++-- internal/config/raw_test.go | 30 ++++++++ 2 files changed, 158 insertions(+), 4 deletions(-) diff --git a/internal/config/fs_test.go b/internal/config/fs_test.go index d32e17216..fff95f5f2 100644 --- a/internal/config/fs_test.go +++ b/internal/config/fs_test.go @@ -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") }) } diff --git a/internal/config/raw_test.go b/internal/config/raw_test.go index 38e29478e..af352336f 100644 --- a/internal/config/raw_test.go +++ b/internal/config/raw_test.go @@ -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()) +}