flamenco/internal/manager/config/settings_test.go
Sybren A. Stüvel d4429d593c Unify task log storage & manager-local storage
The task logs storage system is refactored to use the `local_storage`
package. Configuration options have also changed:

- `task_logs_path` is renamed to `local_manager_storage_path`, to
  emphasise that only the Manager deals with those files, with default
  value `./flamenco-manager-storage`.
- `storage_path` is renamed to `shared_storage_path`, to emphasise this
  is the storage shared between Manager and Workers, with default value
  `./flamenco-shared-storage`.

Task logs are still stored in
`${local_manager_storage_path}/job-{jobUUID[0:4]}/{jobUUID}/task-{taskUUID}.txt`

Manifest task: T99409
2022-07-05 17:58:58 +02:00

97 lines
3.0 KiB
Go

package config
// SPDX-License-Identifier: GPL-3.0-or-later
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestDefaultSettings(t *testing.T) {
config, err := loadConf("nonexistant.yaml")
assert.NotNil(t, err) // should indicate an error to open the file.
// The settings should contain the defaults, though.
assert.Equal(t, latestConfigVersion, config.Meta.Version)
assert.Equal(t, defaultConfig.LocalManagerStoragePath, config.LocalManagerStoragePath)
assert.Equal(t, defaultConfig.DatabaseDSN, config.DatabaseDSN)
assert.Equal(t, false, config.Variables["ffmpeg"].IsTwoWay)
assert.Equal(t, "ffmpeg", config.Variables["ffmpeg"].Values[0].Value)
assert.Equal(t, VariablePlatformLinux, config.Variables["ffmpeg"].Values[0].Platform)
assert.Greater(t, config.BlocklistThreshold, 0)
}
func TestVariableValidation(t *testing.T) {
c := DefaultConfig()
platformless := c.Variables["blender"]
platformless.Values = VariableValues{
VariableValue{Value: "/path/to/blender"},
VariableValue{Platform: "linux", Value: "/valid/path/blender"},
}
c.Variables["blender"] = platformless
c.checkVariables()
assert.Equal(t, c.Variables["blender"].Values[0].Value, "/path/to/blender")
assert.Equal(t, c.Variables["blender"].Values[1].Value, "/valid/path/blender")
}
// TODO: Test two-way variables. Even though they're not currently in the
// default configuration, they should work.
func TestStorageImplicitVariablesWithShaman(t *testing.T) {
c := DefaultConfig(func(c *Conf) {
// Having the Shaman enabled should create an implicit variable "{jobs}" at the Shaman checkout path.
c.SharedStoragePath = "/path/to/shaman/storage"
c.Shaman.Enabled = true
c.Variables["jobs"] = Variable{
IsTwoWay: true,
Values: []VariableValue{
{
Audience: VariableAudienceAll,
Platform: VariablePlatformAll,
Value: "this value should not be seen",
},
},
}
})
assert.NotContains(t, c.Variables, "jobs", "implicit variables should erase existing variables with the same name")
if !assert.Contains(t, c.implicitVariables, "jobs") {
t.FailNow()
}
assert.False(t, c.implicitVariables["jobs"].IsTwoWay)
assert.Equal(t, c.Shaman.CheckoutPath(), c.implicitVariables["jobs"].Values[0].Value)
}
func TestStorageImplicitVariablesWithoutShaman(t *testing.T) {
c := DefaultConfig(func(c *Conf) {
// Having the Shaman disabled should create an implicit variable "{jobs}" at the storage path.
c.SharedStoragePath = "/path/to/shaman/storage"
c.Shaman.Enabled = false
c.Variables["jobs"] = Variable{
IsTwoWay: true,
Values: []VariableValue{
{
Audience: VariableAudienceAll,
Platform: VariablePlatformAll,
Value: "this value should not be seen",
},
},
}
})
assert.NotContains(t, c.Variables, "jobs", "implicit variables should erase existing variables with the same name")
if !assert.Contains(t, c.implicitVariables, "jobs") {
t.FailNow()
}
assert.False(t, c.implicitVariables["jobs"].IsTwoWay)
assert.Equal(t, c.SharedStoragePath, c.implicitVariables["jobs"].Values[0].Value)
}