2022-02-21 17:09:02 +00:00
|
|
|
package config
|
|
|
|
|
2022-03-07 14:26:46 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2022-02-21 17:09:02 +00:00
|
|
|
|
|
|
|
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)
|
2022-02-22 09:33:28 +00:00
|
|
|
assert.Equal(t, defaultConfig.TaskLogsPath, config.TaskLogsPath)
|
|
|
|
assert.Equal(t, defaultConfig.DatabaseDSN, config.DatabaseDSN)
|
2022-02-21 17:09:02 +00:00
|
|
|
|
2022-03-17 10:33:41 +00:00
|
|
|
assert.Equal(t, false, config.Variables["ffmpeg"].IsTwoWay)
|
2022-02-22 12:54:21 +00:00
|
|
|
assert.Equal(t, "ffmpeg", config.Variables["ffmpeg"].Values[0].Value)
|
2022-03-25 15:12:41 +00:00
|
|
|
assert.Equal(t, VariablePlatformLinux, config.Variables["ffmpeg"].Values[0].Platform)
|
2022-02-21 17:09:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-02-22 09:36:17 +00:00
|
|
|
c.checkVariables()
|
2022-02-21 17:09:02 +00:00
|
|
|
|
|
|
|
assert.Equal(t, c.Variables["blender"].Values[0].Value, "/path/to/blender")
|
|
|
|
assert.Equal(t, c.Variables["blender"].Values[1].Value, "/valid/path/blender")
|
|
|
|
}
|
2022-03-17 10:33:41 +00:00
|
|
|
|
|
|
|
// TODO: Test two-way variables. Even though they're not currently in the
|
|
|
|
// default configuration, they should work.
|
2022-03-25 15:19:18 +00:00
|
|
|
|
2022-04-01 11:43:51 +00:00
|
|
|
func TestStorageImplicitVariablesWithShaman(t *testing.T) {
|
2022-03-25 15:19:18 +00:00
|
|
|
c := DefaultConfig(func(c *Conf) {
|
2022-04-01 11:43:51 +00:00
|
|
|
// Having the Shaman enabled should create an implicit variable "{jobs}" at the Shaman checkout path.
|
|
|
|
c.StoragePath = "/path/to/shaman/storage"
|
2022-03-25 15:19:18 +00:00
|
|
|
c.Shaman.Enabled = true
|
2022-03-25 15:40:58 +00:00
|
|
|
|
|
|
|
c.Variables["jobs"] = Variable{
|
|
|
|
IsTwoWay: true,
|
|
|
|
Values: []VariableValue{
|
|
|
|
{
|
|
|
|
Audience: VariableAudienceAll,
|
|
|
|
Platform: VariablePlatformAll,
|
|
|
|
Value: "this value should not be seen",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2022-03-25 15:19:18 +00:00
|
|
|
})
|
|
|
|
|
2022-03-25 15:40:58 +00:00
|
|
|
assert.NotContains(t, c.Variables, "jobs", "implicit variables should erase existing variables with the same name")
|
|
|
|
if !assert.Contains(t, c.implicitVariables, "jobs") {
|
2022-03-25 15:19:18 +00:00
|
|
|
t.FailNow()
|
|
|
|
}
|
2022-03-25 15:40:58 +00:00
|
|
|
assert.False(t, c.implicitVariables["jobs"].IsTwoWay)
|
|
|
|
assert.Equal(t, c.Shaman.CheckoutPath(), c.implicitVariables["jobs"].Values[0].Value)
|
2022-03-25 15:19:18 +00:00
|
|
|
}
|
2022-04-01 11:43:51 +00:00
|
|
|
|
|
|
|
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.StoragePath = "/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.StoragePath, c.implicitVariables["jobs"].Values[0].Value)
|
|
|
|
}
|