github.com/rumpl/bof@v23.0.0-rc.2+incompatible/libnetwork/config/config_test.go (about) 1 package config 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/docker/docker/libnetwork/netlabel" 8 ) 9 10 func TestInvalidConfig(t *testing.T) { 11 _, err := ParseConfig("invalid.toml") 12 if err == nil { 13 t.Fatal("Invalid Configuration file must fail") 14 } 15 } 16 17 func TestConfig(t *testing.T) { 18 _, err := ParseConfig("libnetwork.toml") 19 if err != nil { 20 t.Fatal("Error parsing a valid configuration file :", err) 21 } 22 } 23 24 func TestOptionsLabels(t *testing.T) { 25 c := &Config{} 26 l := []string{ 27 "com.docker.network.key1=value1", 28 "com.docker.storage.key1=value1", 29 "com.docker.network.driver.key1=value1", 30 "com.docker.network.driver.key2=value2", 31 } 32 f := OptionLabels(l) 33 f(c) 34 if len(c.Daemon.Labels) != 3 { 35 t.Fatalf("Expecting 3 labels, seen %d", len(c.Daemon.Labels)) 36 } 37 for _, l := range c.Daemon.Labels { 38 if !strings.HasPrefix(l, netlabel.Prefix) { 39 t.Fatalf("config must accept only libnetwork labels. Not : %s", l) 40 } 41 } 42 } 43 44 func TestValidName(t *testing.T) { 45 if !IsValidName("test") { 46 t.Fatal("Name validation fails for a name that must be accepted") 47 } 48 if IsValidName("") { 49 t.Fatal("Name validation succeeds for a case when it is expected to fail") 50 } 51 if IsValidName(" ") { 52 t.Fatal("Name validation succeeds for a case when it is expected to fail") 53 } 54 }