You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2021/08/11 12:57:42 UTC
[camel-k] branch main updated: fix(api): property leading space
This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new 2e9408a fix(api): property leading space
2e9408a is described below
commit 2e9408a5468a806067caf86941e349dbc7120c02
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Tue Aug 10 16:54:53 2021 +0200
fix(api): property leading space
Closes #2525
---
pkg/apis/camel/v1/integration_types_support.go | 9 +++++++-
.../camel/v1/integration_types_support_test.go | 25 ++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/pkg/apis/camel/v1/integration_types_support.go b/pkg/apis/camel/v1/integration_types_support.go
index 31f09d5..c0df521 100644
--- a/pkg/apis/camel/v1/integration_types_support.go
+++ b/pkg/apis/camel/v1/integration_types_support.go
@@ -148,13 +148,20 @@ func (in *IntegrationSpec) GetConfigurationProperty(property string) string {
if confSpec.Type == "property" && strings.HasPrefix(confSpec.Value, property) {
splitConf := strings.Split(confSpec.Value, "=")
if len(splitConf) > 1 {
- return splitConf[1]
+ return trimFirstLeadingSpace(splitConf[1])
}
}
}
return ""
}
+func trimFirstLeadingSpace(val string) string {
+ if strings.HasPrefix(val, " ") {
+ return val[1:]
+ }
+ return val
+}
+
// AddOrReplaceGeneratedResources --
func (in *IntegrationStatus) AddOrReplaceGeneratedResources(resources ...ResourceSpec) {
newResources := make([]ResourceSpec, 0)
diff --git a/pkg/apis/camel/v1/integration_types_support_test.go b/pkg/apis/camel/v1/integration_types_support_test.go
index 0f02817..6f4d482 100644
--- a/pkg/apis/camel/v1/integration_types_support_test.go
+++ b/pkg/apis/camel/v1/integration_types_support_test.go
@@ -73,3 +73,28 @@ func TestAddDependency(t *testing.T) {
integration.AddDependency("file:dep")
assert.Equal(t, integration.Dependencies, []string{"file:dep"})
}
+
+func TestGetConfigurationProperty(t *testing.T) {
+ integration := IntegrationSpec{}
+ integration.AddConfiguration("property", "key1=value1")
+ integration.AddConfiguration("property", "key2 = value2")
+ integration.AddConfiguration("property", "key3 = value with trailing space ")
+ integration.AddConfiguration("property", "key4 = value with leading space")
+ integration.AddConfiguration("property", "key5 = ")
+ integration.AddConfiguration("property", "key6=")
+
+ missing := integration.GetConfigurationProperty("missing")
+ assert.Equal(t, "", missing)
+ v1 := integration.GetConfigurationProperty("key")
+ assert.Equal(t, "value1", v1)
+ v2 := integration.GetConfigurationProperty("key2")
+ assert.Equal(t, "value2", v2)
+ v3 := integration.GetConfigurationProperty("key3")
+ assert.Equal(t, "value with trailing space ", v3)
+ v4 := integration.GetConfigurationProperty("key4")
+ assert.Equal(t, " value with leading space", v4)
+ v5 := integration.GetConfigurationProperty("key5")
+ assert.Equal(t, "", v5)
+ v6 := integration.GetConfigurationProperty("key6")
+ assert.Equal(t, "", v6)
+}