forked from JamesClonk/backman
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from schefDev/develop
improve URI parsing for elasticsearch bindings * alternative determin…
- Loading branch information
Showing
3 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package service | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/swisscom/backman/config" | ||
) | ||
|
||
func Test_Service_EnrichBinding(t *testing.T) { | ||
config.SetConfigFile("_fixtures/config_without_bindings.json") | ||
|
||
os.Unsetenv("SERVICE_BINDING_ROOT") | ||
|
||
c := config.Get() | ||
mergeVCAPServices() | ||
|
||
elasticsearchServiceConfig := c.Services["my-elasticsearch"] | ||
|
||
// without enrichBinding is port undefined | ||
assert.Equal(t, 0, elasticsearchServiceConfig.Binding.Port) | ||
|
||
// if port is defined in uri, it is determined from there | ||
elasticsearchServiceConfig.Binding = enrichBinding(elasticsearchServiceConfig.Binding) | ||
assert.Equal(t, 443, elasticsearchServiceConfig.Binding.Port) | ||
|
||
// if no port is defined in uri, it is determined by schema/protocol | ||
elasticsearchServiceConfig.Binding.Host = "https://0c061730-1b19-424b-8efd-349fd40957a0.yolo.elasticsearch.lyra-836.appcloud.swisscom.com" | ||
elasticsearchServiceConfig.Binding.URI = elasticsearchServiceConfig.Binding.Host | ||
elasticsearchServiceConfig.Binding.Port = 0 | ||
elasticsearchServiceConfig.Binding = enrichBinding(elasticsearchServiceConfig.Binding) | ||
assert.Equal(t, 443, elasticsearchServiceConfig.Binding.Port) | ||
|
||
// if no port is defined in uri, it is determined by schema/protocol | ||
elasticsearchServiceConfig.Binding.Host = "http://0c061730-1b19-424b-8efd-349fd40957a0.yolo.elasticsearch.lyra-836.appcloud.swisscom.com" | ||
elasticsearchServiceConfig.Binding.URI = elasticsearchServiceConfig.Binding.Host | ||
elasticsearchServiceConfig.Binding.Port = 0 | ||
elasticsearchServiceConfig.Binding = enrichBinding(elasticsearchServiceConfig.Binding) | ||
assert.Equal(t, 80, elasticsearchServiceConfig.Binding.Port) | ||
|
||
// if no port is defined in uri, it is determined by schema/protocol, but only known ones | ||
elasticsearchServiceConfig.Binding.Host = "nonehttp://0c061730-1b19-424b-8efd-349fd40957a0.yolo.elasticsearch.lyra-836.appcloud.swisscom.com" | ||
elasticsearchServiceConfig.Binding.URI = elasticsearchServiceConfig.Binding.Host | ||
elasticsearchServiceConfig.Binding.Port = 0 | ||
elasticsearchServiceConfig.Binding = enrichBinding(elasticsearchServiceConfig.Binding) | ||
assert.Equal(t, 0, elasticsearchServiceConfig.Binding.Port) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package service | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/swisscom/backman/config" | ||
) | ||
|
||
func Test_Service_MergeVCAPServices(t *testing.T) { | ||
config.SetConfigFile("_fixtures/config_without_bindings.json") | ||
|
||
os.Unsetenv("SERVICE_BINDING_ROOT") | ||
|
||
c := config.Get() | ||
mergeVCAPServices() | ||
|
||
assert.Equal(t, "postgres", c.Services["my_postgres_db"].Binding.Type) | ||
assert.Equal(t, "127.0.0.1", c.Services["my_postgres_db"].Binding.Host) | ||
assert.Equal(t, 5432, c.Services["my_postgres_db"].Binding.Port) | ||
assert.Equal(t, "dev-user", c.Services["my_postgres_db"].Binding.Username) | ||
assert.Equal(t, "dev-secret", c.Services["my_postgres_db"].Binding.Password) | ||
assert.Equal(t, "postgres://dev-user:dev-secret@127.0.0.1:5432/my_postgres_db?sslmode=disable", c.Services["my_postgres_db"].Binding.URI) | ||
assert.Equal(t, "https://0c061730-1b19-424b-8efd-349fd40957a0.yolo.elasticsearch.lyra-836.appcloud.swisscom.com:443", c.Services["my-elasticsearch"].Binding.URI) | ||
} |