From 4a201d47b48a201a22869059eaf4d57c0b730b3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 29 Aug 2022 17:28:40 +0200 Subject: [PATCH] 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. --- internal/manager/config/config_test.go | 20 ++++++++++++++++ .../test_files/config_with_backslashes.yaml | 24 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 internal/manager/config/config_test.go create mode 100644 internal/manager/config/test_files/config_with_backslashes.yaml diff --git a/internal/manager/config/config_test.go b/internal/manager/config/config_test.go new file mode 100644 index 00000000..9e38d320 --- /dev/null +++ b/internal/manager/config/config_test.go @@ -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"]) +} diff --git a/internal/manager/config/test_files/config_with_backslashes.yaml b/internal/manager/config/test_files/config_with_backslashes.yaml new file mode 100644 index 00000000..a702e96d --- /dev/null +++ b/internal/manager/config/test_files/config_with_backslashes.yaml @@ -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"