2015-05-23 00:52:02 -04:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2015-06-14 12:03:42 -04:00
|
|
|
"strings"
|
2015-05-23 00:52:02 -04:00
|
|
|
"testing"
|
2015-05-15 18:23:59 -04:00
|
|
|
|
2021-04-05 20:24:47 -04:00
|
|
|
"github.com/docker/docker/libnetwork/netlabel"
|
2015-05-23 00:52:02 -04:00
|
|
|
)
|
|
|
|
|
2015-06-14 12:03:42 -04:00
|
|
|
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)
|
2022-09-23 13:40:11 -04:00
|
|
|
if len(c.Labels) != 3 {
|
|
|
|
t.Fatalf("Expecting 3 labels, seen %d", len(c.Labels))
|
2015-06-14 12:03:42 -04:00
|
|
|
}
|
2022-09-23 13:40:11 -04:00
|
|
|
for _, l := range c.Labels {
|
2015-06-14 12:03:42 -04:00
|
|
|
if !strings.HasPrefix(l, netlabel.Prefix) {
|
|
|
|
t.Fatalf("config must accept only libnetwork labels. Not : %s", l)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-14 12:00:27 -04:00
|
|
|
|
|
|
|
func TestValidName(t *testing.T) {
|
2017-02-01 21:17:29 -05:00
|
|
|
if !IsValidName("test") {
|
2017-02-01 21:17:17 -05:00
|
|
|
t.Fatal("Name validation fails for a name that must be accepted")
|
|
|
|
}
|
2017-02-01 21:17:29 -05:00
|
|
|
if IsValidName("") {
|
2017-02-01 21:17:17 -05:00
|
|
|
t.Fatal("Name validation succeeds for a case when it is expected to fail")
|
|
|
|
}
|
2017-02-01 21:17:29 -05:00
|
|
|
if IsValidName(" ") {
|
2017-02-01 21:17:17 -05:00
|
|
|
t.Fatal("Name validation succeeds for a case when it is expected to fail")
|
2015-09-11 14:02:16 -04:00
|
|
|
}
|
2015-06-14 12:00:27 -04:00
|
|
|
}
|