mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
39bcaee47b
* additional * ambiguous * anonymous * anything * application * because * before * building * capabilities * circumstances * commit * committer * compresses * concatenated * config * container * container's * current * definition * delimiter * disassociates * discovery * distributed * doesnotexist * downloads * duplicates * either * enhancing * enumerate * escapable * exactly * expect * expectations * expected * explicitly * false * filesystem * following * forbidden * git with * healthcheck * ignore * independent * inheritance * investigating * irrelevant * it * logging * looking * membership * mimic * minimum * modify * mountpoint * multiline * notifier * outputting * outside * overridden * override * parsable * plugins * precedence * propagation * provided * provides * registries * repositories * returning * settings * should * signals * someone * something * specifically * successfully * synchronize * they've * thinking * uninitialized * unintentionally * unmarshaling * unnamed * unreferenced * verify Signed-off-by: Josh Soref <jsoref@gmail.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
111 lines
3.1 KiB
Go
111 lines
3.1 KiB
Go
package discovery
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestDiscoveryOpts(t *testing.T) {
|
|
clusterOpts := map[string]string{"discovery.heartbeat": "10", "discovery.ttl": "5"}
|
|
heartbeat, ttl, err := discoveryOpts(clusterOpts)
|
|
if err == nil {
|
|
t.Fatal("discovery.ttl < discovery.heartbeat must fail")
|
|
}
|
|
|
|
clusterOpts = map[string]string{"discovery.heartbeat": "10", "discovery.ttl": "10"}
|
|
heartbeat, ttl, err = discoveryOpts(clusterOpts)
|
|
if err == nil {
|
|
t.Fatal("discovery.ttl == discovery.heartbeat must fail")
|
|
}
|
|
|
|
clusterOpts = map[string]string{"discovery.heartbeat": "-10", "discovery.ttl": "10"}
|
|
heartbeat, ttl, err = discoveryOpts(clusterOpts)
|
|
if err == nil {
|
|
t.Fatal("negative discovery.heartbeat must fail")
|
|
}
|
|
|
|
clusterOpts = map[string]string{"discovery.heartbeat": "10", "discovery.ttl": "-10"}
|
|
heartbeat, ttl, err = discoveryOpts(clusterOpts)
|
|
if err == nil {
|
|
t.Fatal("negative discovery.ttl must fail")
|
|
}
|
|
|
|
clusterOpts = map[string]string{"discovery.heartbeat": "invalid"}
|
|
heartbeat, ttl, err = discoveryOpts(clusterOpts)
|
|
if err == nil {
|
|
t.Fatal("invalid discovery.heartbeat must fail")
|
|
}
|
|
|
|
clusterOpts = map[string]string{"discovery.ttl": "invalid"}
|
|
heartbeat, ttl, err = discoveryOpts(clusterOpts)
|
|
if err == nil {
|
|
t.Fatal("invalid discovery.ttl must fail")
|
|
}
|
|
|
|
clusterOpts = map[string]string{"discovery.heartbeat": "10", "discovery.ttl": "20"}
|
|
heartbeat, ttl, err = discoveryOpts(clusterOpts)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if heartbeat != 10*time.Second {
|
|
t.Fatalf("Heartbeat - Expected : %v, Actual : %v", 10*time.Second, heartbeat)
|
|
}
|
|
|
|
if ttl != 20*time.Second {
|
|
t.Fatalf("TTL - Expected : %v, Actual : %v", 20*time.Second, ttl)
|
|
}
|
|
|
|
clusterOpts = map[string]string{"discovery.heartbeat": "10"}
|
|
heartbeat, ttl, err = discoveryOpts(clusterOpts)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if heartbeat != 10*time.Second {
|
|
t.Fatalf("Heartbeat - Expected : %v, Actual : %v", 10*time.Second, heartbeat)
|
|
}
|
|
|
|
expected := 10 * defaultDiscoveryTTLFactor * time.Second
|
|
if ttl != expected {
|
|
t.Fatalf("TTL - Expected : %v, Actual : %v", expected, ttl)
|
|
}
|
|
|
|
clusterOpts = map[string]string{"discovery.ttl": "30"}
|
|
heartbeat, ttl, err = discoveryOpts(clusterOpts)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if ttl != 30*time.Second {
|
|
t.Fatalf("TTL - Expected : %v, Actual : %v", 30*time.Second, ttl)
|
|
}
|
|
|
|
expected = 30 * time.Second / defaultDiscoveryTTLFactor
|
|
if heartbeat != expected {
|
|
t.Fatalf("Heartbeat - Expected : %v, Actual : %v", expected, heartbeat)
|
|
}
|
|
|
|
discoveryTTL := fmt.Sprintf("%d", defaultDiscoveryTTLFactor-1)
|
|
clusterOpts = map[string]string{"discovery.ttl": discoveryTTL}
|
|
heartbeat, ttl, err = discoveryOpts(clusterOpts)
|
|
if err == nil && heartbeat == 0 {
|
|
t.Fatal("discovery.heartbeat must be positive")
|
|
}
|
|
|
|
clusterOpts = map[string]string{}
|
|
heartbeat, ttl, err = discoveryOpts(clusterOpts)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if heartbeat != defaultDiscoveryHeartbeat {
|
|
t.Fatalf("Heartbeat - Expected : %v, Actual : %v", defaultDiscoveryHeartbeat, heartbeat)
|
|
}
|
|
|
|
expected = defaultDiscoveryHeartbeat * defaultDiscoveryTTLFactor
|
|
if ttl != expected {
|
|
t.Fatalf("TTL - Expected : %v, Actual : %v", expected, ttl)
|
|
}
|
|
}
|