Cleanup: add unit test for parsing backslashes in variable values

Backslashes can be included in two ways, as-is (which works fine) and
between double quotes (in which case they need escaping). This test checks
for both.
This commit is contained in:
Sybren A. Stüvel 2022-08-29 17:28:40 +02:00
parent 0c91fe93d0
commit 4a201d47b4
2 changed files with 44 additions and 0 deletions

@ -0,0 +1,20 @@
package config
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestVariablesWithBackslashes(t *testing.T) {
c, err := loadConf("test_files/config_with_backslashes.yaml")
require.NoError(t, err)
vars := c.VariablesLookup[VariableAudienceUsers]
expectSingle := `C:\Downloads\blender-1.0\blender.exe`
expectDouble := `C:\\Downloads\\blender-1.0\\blender.exe`
assert.Equal(t, expectSingle, vars["single-backslash"]["blender"])
assert.Equal(t, expectDouble, vars["double-backslash"]["blender"])
assert.Equal(t, expectSingle, vars["quoted-double-backslash"]["blender"])
}

@ -0,0 +1,24 @@
# File for use in unit tests
#
# This file has variable definitions with various ways to include backslashes in
# values.
_meta:
version: 3
manager_name: Backslash Tester
database: flamenco-manager-backslash-tester.sqlite
listen: :8123
autodiscoverable: false
local_manager_storage_path: ./flamenco-manager-storage
shared_storage_path: ./tmp/flamenco-shared-storage
shaman:
enabled: false
variables:
blender:
values:
- platform: single-backslash
value: C:\Downloads\blender-1.0\blender.exe
- platform: double-backslash
value: C:\\Downloads\\blender-1.0\\blender.exe
- platform: quoted-double-backslash
value: "C:\\Downloads\\blender-1.0\\blender.exe"