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 (
|
2022-07-21 14:41:40 +00:00
|
|
|
"sync"
|
2022-02-21 17:09:02 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-07-13 10:45:55 +00:00
|
|
|
"git.blender.org/flamenco/pkg/crosspath"
|
2022-02-21 17:09:02 +00:00
|
|
|
"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-07-05 15:58:58 +00:00
|
|
|
assert.Equal(t, defaultConfig.LocalManagerStoragePath, config.LocalManagerStoragePath)
|
2022-02-22 09:33:28 +00:00
|
|
|
assert.Equal(t, defaultConfig.DatabaseDSN, config.DatabaseDSN)
|
2022-02-21 17:09:02 +00:00
|
|
|
|
2022-07-22 14:05:18 +00:00
|
|
|
assert.Equal(t, false, config.Variables["blender"].IsTwoWay)
|
|
|
|
assert.Equal(t, "blender "+DefaultBlenderArguments, config.Variables["blender"].Values[0].Value)
|
|
|
|
assert.Equal(t, VariablePlatformLinux, config.Variables["blender"].Values[0].Platform)
|
2022-06-17 13:03:15 +00:00
|
|
|
|
|
|
|
assert.Greater(t, config.BlocklistThreshold, 0)
|
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
|
|
|
|
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.
|
2022-07-05 15:58:58 +00:00
|
|
|
c.SharedStoragePath = "/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{
|
2022-07-21 14:41:40 +00:00
|
|
|
IsTwoWay: false,
|
2022-03-25 15:40:58 +00:00
|
|
|
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)
|
2022-07-13 10:45:55 +00:00
|
|
|
assert.Equal(t,
|
|
|
|
crosspath.ToSlash(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.
|
2022-07-05 15:58:58 +00:00
|
|
|
c.SharedStoragePath = "/path/to/shaman/storage"
|
2022-04-01 11:43:51 +00:00
|
|
|
c.Shaman.Enabled = false
|
|
|
|
|
|
|
|
c.Variables["jobs"] = Variable{
|
2022-07-21 14:41:40 +00:00
|
|
|
IsTwoWay: false,
|
2022-04-01 11:43:51 +00:00
|
|
|
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)
|
2022-07-13 10:45:55 +00:00
|
|
|
assert.Equal(t,
|
|
|
|
crosspath.ToSlash(c.SharedStoragePath),
|
|
|
|
c.implicitVariables["jobs"].Values[0].Value)
|
2022-04-01 11:43:51 +00:00
|
|
|
}
|
2022-07-21 14:41:40 +00:00
|
|
|
|
|
|
|
func TestExpandVariables(t *testing.T) {
|
|
|
|
c := DefaultConfig(func(c *Conf) {
|
|
|
|
c.Variables["demo"] = Variable{
|
|
|
|
Values: []VariableValue{
|
|
|
|
{Value: "demo-value", Audience: VariableAudienceAll, Platform: VariablePlatformDarwin},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
c.Variables["ffmpeg"] = Variable{
|
|
|
|
Values: []VariableValue{
|
|
|
|
{Value: "/path/to/ffmpeg", Audience: VariableAudienceUsers, Platform: VariablePlatformLinux},
|
|
|
|
{Value: "/path/to/ffmpeg/on/darwin", Audience: VariableAudienceUsers, Platform: VariablePlatformDarwin},
|
|
|
|
{Value: "C:/flamenco/ffmpeg", Audience: VariableAudienceUsers, Platform: VariablePlatformWindows},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
feeder := make(chan string, 1)
|
|
|
|
receiver := make(chan string, 1)
|
|
|
|
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
c.ExpandVariables(feeder, receiver, VariableAudienceUsers, VariablePlatformWindows)
|
|
|
|
}()
|
|
|
|
|
|
|
|
feeder <- "unchanged value"
|
|
|
|
assert.Equal(t, "unchanged value", <-receiver)
|
|
|
|
|
|
|
|
feeder <- "{ffmpeg}"
|
|
|
|
assert.Equal(t, "C:/flamenco/ffmpeg", <-receiver)
|
|
|
|
|
|
|
|
feeder <- "{demo}"
|
|
|
|
assert.Equal(t, "{demo}", <-receiver, "missing value on the platform should not be replaced")
|
|
|
|
|
|
|
|
close(feeder)
|
|
|
|
wg.Wait()
|
|
|
|
close(receiver)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestExpandVariablesWithTwoWay(t *testing.T) {
|
|
|
|
|
|
|
|
c := DefaultConfig(func(c *Conf) {
|
|
|
|
// Mock that the Manager is running on Linux right now.
|
|
|
|
c.currentGOOS = VariablePlatformLinux
|
|
|
|
|
|
|
|
// Register one variable in the same way that the implicit 'jobs' variable is registered.
|
|
|
|
c.Variables["locally-set-path"] = Variable{
|
|
|
|
Values: []VariableValue{
|
|
|
|
{Value: "/path/on/linux", Platform: VariablePlatformAll, Audience: VariableAudienceAll},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
// This two-way variable should be used to translate the path as well.
|
|
|
|
c.Variables["platform-specifics"] = Variable{
|
|
|
|
IsTwoWay: true,
|
|
|
|
Values: []VariableValue{
|
|
|
|
{Value: "/path/on/linux", Platform: VariablePlatformLinux, Audience: VariableAudienceWorkers},
|
|
|
|
{Value: "/path/on/darwin", Platform: VariablePlatformDarwin, Audience: VariableAudienceWorkers},
|
|
|
|
{Value: "C:/path/on/windows", Platform: VariablePlatformWindows, Audience: VariableAudienceWorkers},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
feeder := make(chan string, 1)
|
|
|
|
receiver := make(chan string, 1)
|
|
|
|
|
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer wg.Done()
|
|
|
|
// Always target a different-than-current target platform.
|
|
|
|
c.ExpandVariables(feeder, receiver, VariableAudienceWorkers, VariablePlatformWindows)
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Simple two-way variable replacement.
|
|
|
|
feeder <- "/path/on/linux/file.txt"
|
|
|
|
assert.Equal(t, "C:/path/on/windows/file.txt", <-receiver)
|
|
|
|
|
|
|
|
// {locally-set-path} expands to a value that's then further replaced by a two-way variable.
|
|
|
|
feeder <- "{locally-set-path}/should/be/remapped"
|
|
|
|
assert.Equal(t, "C:/path/on/windows/should/be/remapped", <-receiver)
|
|
|
|
|
|
|
|
close(feeder)
|
|
|
|
wg.Wait()
|
|
|
|
close(receiver)
|
|
|
|
}
|