Ejemplo n.º 1
0
func TestConstructServer(t *testing.T) {
	config := NewConfig(routing.DefaultMatcherFactory())

	server := config.ConstructServer(Host{
		Address: "localhost:8080",
	})

	if server.Address != "localhost:8080" {
		t.Errorf("should construct server accurately")
	}
}
Ejemplo n.º 2
0
func TestConstructRule(t *testing.T) {
	config := NewConfig(routing.DefaultMatcherFactory())
	config.AddPool(butcheryPool())
	config.AddTrie(meatTrie())

	test := Rule{
		Name:  "test",
		Type:  "anyhow",
		Value: "www.ooyala.com",
		Next:  "meatTrie",
		Pool:  "butcheryPool",
	}

	parsed := config.ConstructRule(test)

	if parsed.NextPtr != config.Tries["meatTrie"] || parsed.PoolPtr != config.Pools["butcheryPool"] {
		t.Errorf("should construct rule accurately")
	}
}
Ejemplo n.º 3
0
func TestConstructPoolConfig(t *testing.T) {
	config := NewConfig(routing.DefaultMatcherFactory())

	test := Pool{
		Name: "Aloha!",
		Config: PoolConfig{
			HealthzEvery:   "Saturn",
			HealthzTimeout: "Jupiter",
			RequestTimeout: "Mars",
			Status:         "Excellent",
		},
	}

	parsed := config.ConstructPoolConfig(test)

	if parsed.HealthzEvery == 0 || parsed.HealthzTimeout == 0 || parsed.RequestTimeout == 0 ||
		!backend.IsValidStatus(parsed.Status) {
		t.Errorf("should default to sane defaults")
	}
}
Ejemplo n.º 4
0
func TestConstructRuleBadMatcher(t *testing.T) {
	config := NewConfig(routing.DefaultMatcherFactory())
	config.AddPool(butcheryPool())
	config.AddTrie(meatTrie())

	test := Rule{
		Name:  "test",
		Type:  "anyhow",
		Value: "www.ooyala.com",
		Next:  "meatTrie",
		Pool:  "butcheryPool",
	}

	defer func() {
		if r := recover(); r != nil {
			t.Errorf("should silently ignore bad rules")
		}
	}()
	config.ConstructRule(test)
}
Ejemplo n.º 5
0
func TestConstructRuleEmpty(t *testing.T) {
	config := NewConfig(routing.DefaultMatcherFactory())

	test := Rule{
		Name:  "test",
		Type:  "host",
		Value: "www.ooyala.com",
		Next:  "",
		Pool:  "",
	}

	defer func() {
		if r := recover(); r != nil {
			t.Errorf("should silently ignore empty rule")
		}
	}()
	parsed := config.ConstructRule(test)

	if parsed.Dummy != true {
		t.Errorf("should return dummy rule")
	}
}
Ejemplo n.º 6
0
func TestConstructRuleBadNext(t *testing.T) {
	config := NewConfig(routing.DefaultMatcherFactory())
	config.AddPool(butcheryPool())

	test := Rule{
		Name:  "test",
		Type:  "host",
		Value: "www.ooyala.com",
		Next:  "meatTrie",
		Pool:  "butcherPool",
	}

	defer func() {
		if r := recover(); r != nil {
			t.Errorf("should silently ignore non existent next")
		}
	}()
	parsed := config.ConstructRule(test)

	if parsed.NextPtr.Dummy != true {
		t.Errorf("should use dummy trie")
	}
}