From a6fa40e1772dd29d919dc62be071a95b871facbd Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Tue, 28 Nov 2023 17:32:25 -0500 Subject: [PATCH] fix(vm,lxc): file ID validator to allow `.` in a storage name (#750) fix(vm,lxc): file ID validator to allow `.` in a storage name Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- proxmoxtf/resource/validator/file.go | 2 +- proxmoxtf/resource/validator/file_test.go | 44 +++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 proxmoxtf/resource/validator/file_test.go diff --git a/proxmoxtf/resource/validator/file.go b/proxmoxtf/resource/validator/file.go index 75f9af42..842f839b 100644 --- a/proxmoxtf/resource/validator/file.go +++ b/proxmoxtf/resource/validator/file.go @@ -39,7 +39,7 @@ func FileID() schema.SchemaValidateDiagFunc { } if v != "" { - r := regexp.MustCompile(`^(?i)[a-z\d\-_]+:([a-z\d\-_]+/)?.+$`) + r := regexp.MustCompile(`^(?i)[a-z\d\-_\.]+:([a-z\d\-_]+/)?.+$`) ok := r.MatchString(v) if !ok { diff --git a/proxmoxtf/resource/validator/file_test.go b/proxmoxtf/resource/validator/file_test.go new file mode 100644 index 00000000..0c2157ad --- /dev/null +++ b/proxmoxtf/resource/validator/file_test.go @@ -0,0 +1,44 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +package validator + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestFileID(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + value string + valid bool + }{ + {"empty", "", true}, + {"invalid", "invalid", false}, + {"valid", "local:vztmpl/zen-dns-0.1.tar.zst", true}, + {"valid when datastore name has dots", "terraform.proxmox.storage.compute.zen:vztmpl/zen-dns-0.1.tar.zst", true}, + } + + for _, tt := range tests { + tt := tt + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + + f := FileID() + res := f(tt.value, nil) + + if tt.valid { + require.Empty(t, res, "validate: '%s'", tt.value) + } else { + require.NotEmpty(t, res, "validate: '%s'", tt.value) + } + }) + } +}