fix: service env truncation for multiple delimiters (#193)

Closes #121 
* test: adds failing test for service env with multiple delimiters
* fix: mapping of multiple delimiters for string slice to map
This commit is contained in:
Manuel Vogel 2019-10-06 12:11:11 +02:00 committed by GitHub
parent f3e27203d1
commit cb9c327ae4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -237,6 +237,7 @@ func TestAccDockerService_fullSpec(t *testing.T) {
env = {
MYFOO = "BAR"
URI = "/api-call?param1=value1"
}
dir = "/root"
@ -398,6 +399,7 @@ func TestAccDockerService_fullSpec(t *testing.T) {
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.args.0", "-las"),
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.hostname", "my-fancy-service"),
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.env.MYFOO", "BAR"),
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.env.URI", "/api-call?param1=value1"),
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.dir", "/root"),
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.user", "root"),
resource.TestCheckResourceAttr("docker_service.foo", "task_spec.0.container_spec.0.groups.0", "docker"),

View file

@ -516,14 +516,16 @@ func newStringSet(f schema.SchemaSetFunc, in []string) *schema.Set {
return schema.NewSet(f, out)
}
// mapStringSliceToMap maps a slice with '=' delimiter to as map: e.g. 'foo=bar' -> foo = "bar"
// mapStringSliceToMap maps a slice with '=' delimiter to as map: e.g.
// - 'foo=bar' -> foo = "bar"
// - 'foo=bar?p=baz' -> foo = "bar?p=baz"
func mapStringSliceToMap(in []string) map[string]string {
mapped := make(map[string]string, len(in))
for _, v := range in {
if len(v) > 0 {
splitted := strings.Split(v, "=")
key := splitted[0]
value := splitted[1]
value := strings.Join(splitted[1:], "=")
mapped[key] = value
}
}