mirror of
https://github.com/moby/moby.git
synced 2026-08-07 16:41:50 +00:00
This utility was not used for "Config", but for Networks and Endpoints.
Having this utility made it look like more than it was, and the related
test was effectively testing stdlib.
Abstracting the validation also was hiding that, while validation does
not allow "empty" names, it happily allows leading/trailing whitespace,
and does not remove that before creating networks or endpoints;
docker network create "bridge "
docker network create "bridge "
docker network create "bridge "
docker network create " bridge "
docker network create " bridge "
docker network create " bridge"
docker network ls --filter driver=bridge
NETWORK ID NAME DRIVER SCOPE
d4d53210f185 bridge bridge local
e9afba0d99de bridge bridge local
69fb7a7ba67c bridge bridge local
a452bf065403 bridge bridge local
49d96c59061d bridge bridge local
8eae1c4be12c bridge bridge local
86dd65b881b9 bridge bridge local
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
29 lines
599 B
Go
29 lines
599 B
Go
package config
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/docker/docker/libnetwork/netlabel"
|
|
)
|
|
|
|
func TestOptionsLabels(t *testing.T) {
|
|
c := &Config{}
|
|
l := []string{
|
|
"com.docker.network.key1=value1",
|
|
"com.docker.storage.key1=value1",
|
|
"com.docker.network.driver.key1=value1",
|
|
"com.docker.network.driver.key2=value2",
|
|
}
|
|
f := OptionLabels(l)
|
|
f(c)
|
|
if len(c.Labels) != 3 {
|
|
t.Fatalf("Expecting 3 labels, seen %d", len(c.Labels))
|
|
}
|
|
for _, l := range c.Labels {
|
|
if !strings.HasPrefix(l, netlabel.Prefix) {
|
|
t.Fatalf("config must accept only libnetwork labels. Not : %s", l)
|
|
}
|
|
}
|
|
}
|