This is an automated email from the ASF dual-hosted git repository. pcongiusti pushed a commit to branch release-1.5.x in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/release-1.5.x by this push: new 7202476 fix(api): property leading space 7202476 is described below commit 7202476308c21ab7620efc3e6fc9697bdb007ecf Author: Pasquale Congiusti <pasquale.congiu...@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) +}