Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
fix: resource placeholder substitution
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Würbach <johannes.wuerbach@googlemail.com>
  • Loading branch information
johanneswuerbach committed Jan 19, 2024
1 parent f1f3de2 commit 8ac6d51
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/humanitec/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
20 changes: 20 additions & 0 deletions internal/humanitec/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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) {
Expand Down

0 comments on commit 8ac6d51

Please sign in to comment.