From 8ac6d51b4e7f30149be31f6039aca764d5a85052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20W=C3=BCrbach?= Date: Fri, 19 Jan 2024 17:55:49 +0100 Subject: [PATCH] fix: resource placeholder substitution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Johannes Würbach --- internal/humanitec/templates.go | 2 +- internal/humanitec/templates_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/internal/humanitec/templates.go b/internal/humanitec/templates.go index f573ab1..d5a3244 100644 --- a/internal/humanitec/templates.go +++ b/internal/humanitec/templates.go @@ -153,7 +153,7 @@ func (ctx *templatesContext) mapVar(ref string) string { // END (DEPRECATED) if hasAnnotation && strings.HasPrefix(resId, "shared.") && (res.Class != "" && res.Class != "default") { - resId = "shared." + resName + "-class-" + res.Class + resId = resId + "-class-" + res.Class } if resId != "" { diff --git a/internal/humanitec/templates_test.go b/internal/humanitec/templates_test.go index 685904e..f425d25 100644 --- a/internal/humanitec/templates_test.go +++ b/internal/humanitec/templates_test.go @@ -126,6 +126,23 @@ func TestSubstitute(t *testing.T) { "service-a": score.ResourceSpec{ Type: "service", }, + "shared-res": score.ResourceSpec{ + Type: "s3", + Metadata: score.ResourceMeta{ + Annotations: map[string]string{ + AnnotationLabelResourceId: "shared.main-s3", + }, + }, + }, + "shared-res-admin": score.ResourceSpec{ + Type: "s3", + Class: "admin", + Metadata: score.ResourceMeta{ + Annotations: map[string]string{ + AnnotationLabelResourceId: "shared.main-s3", + }, + }, + }, } var ext = extensions.HumanitecResourcesSpecs{ @@ -150,6 +167,9 @@ func TestSubstitute(t *testing.T) { assert.Equal(t, "postgresql://${externals.db.user}:${externals.db.password}@${externals.db.host}:${externals.db.port}/${externals.db.name}", ctx.Substitute("postgresql://${resources.db.user}:${resources.db.password}@${resources.db.host}:${resources.db.port}/${resources.db.name}")) + + assert.Equal(t, "${shared.main-s3.name}", ctx.Substitute("${resources.shared-res.name}")) + assert.Equal(t, "${shared.main-s3-class-admin.name}", ctx.Substitute("${resources.shared-res-admin.name}")) } func TestSubstituteAll(t *testing.T) {