1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/libnetwork/config/config_test.go
Anca Iordache 00f9b23c3a
libnetwork: remove external DS-based host discovery
Signed-off-by: Anca Iordache <anca.iordache@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-01-06 18:28:26 +01:00

54 lines
1.2 KiB
Go

package config
import (
"strings"
"testing"
"github.com/docker/docker/libnetwork/netlabel"
)
func TestInvalidConfig(t *testing.T) {
_, err := ParseConfig("invalid.toml")
if err == nil {
t.Fatal("Invalid Configuration file must fail")
}
}
func TestConfig(t *testing.T) {
_, err := ParseConfig("libnetwork.toml")
if err != nil {
t.Fatal("Error parsing a valid configuration file :", err)
}
}
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.Daemon.Labels) != 3 {
t.Fatalf("Expecting 3 labels, seen %d", len(c.Daemon.Labels))
}
for _, l := range c.Daemon.Labels {
if !strings.HasPrefix(l, netlabel.Prefix) {
t.Fatalf("config must accept only libnetwork labels. Not : %s", l)
}
}
}
func TestValidName(t *testing.T) {
if !IsValidName("test") {
t.Fatal("Name validation fails for a name that must be accepted")
}
if IsValidName("") {
t.Fatal("Name validation succeeds for a case when it is expected to fail")
}
if IsValidName(" ") {
t.Fatal("Name validation succeeds for a case when it is expected to fail")
}
}