Example #1
0
func TestManageRoutesSpecValidateMissingCidr(t *testing.T) {
	r := ManageRoutesSpec{
		Instance: "SELF",
	}
	err := r.Validate(im1, &FakeRouteTableManager{}, "foo", emptyHealthchecks, emptyHealthchecks)
	testhelpers.CheckOneMultiError(t, err, "cidr is not defined in foo")
}
Example #2
0
func TestHealthcheckValidateNoType(t *testing.T) {
	h := Healthcheck{
		Destination: "127.0.0.1",
	}
	err := h.Validate("foo", false)
	testhelpers.CheckOneMultiError(t, err, "No healthcheck type set")
}
Example #3
0
func TestRouteTableFindSpecValidateNoConfig(t *testing.T) {
	r := RouteTableFindSpec{
		Type: "by_tag",
	}
	err := r.Validate("foo")
	testhelpers.CheckOneMultiError(t, err, "Route find spec foo needs config")
}
Example #4
0
func TestHealthcheckValidateFailNoDestination(t *testing.T) {
	h := Healthcheck{
		Type: "ping",
	}
	err := h.Validate("foo", false)
	testhelpers.CheckOneMultiError(t, err, "Healthcheck foo has no destination set")
}
Example #5
0
func TestGetFiltersListForSpecWrongType(t *testing.T) {
	c := make(map[string]interface{})
	c["filters"] = "foo"
	spec := RouteTableFindSpec{Config: c}
	_, err := getFiltersListForSpec(spec)
	testhelpers.CheckOneMultiError(t, err, "unexpected type string for 'filters' key")
}
Example #6
0
func TestConfigValidateEmptyRouteTables(t *testing.T) {
	r := make(map[string]*RouteTable)
	c := Config{
		RouteTables: r,
	}
	err := c.Validate(tim, rtm)
	testhelpers.CheckOneMultiError(t, err, "No route_tables defined in config")
}
Example #7
0
func TestHealthcheckValidateRemoteWithDestFails(t *testing.T) {
	h := Healthcheck{
		Type:        "ping",
		Destination: "127.0.0.1",
	}
	err := h.Validate("foo", true)
	testhelpers.CheckOneMultiError(t, err, "Remote healthcheck foo cannot have destination set")
}
Example #8
0
func TestHealthcheckValidateFailDestination(t *testing.T) {
	h := Healthcheck{
		Type:        "ping",
		Destination: "www.google.com",
	}
	err := h.Validate("foo", false)
	testhelpers.CheckOneMultiError(t, err, "Healthcheck foo destination 'www.google.com' does not parse as an IP address")
}
Example #9
0
func TestHealthcheckValidateFailType(t *testing.T) {
	h := Healthcheck{
		Type:        "notping",
		Destination: "127.0.0.1",
	}
	err := h.Validate("foo", false)
	testhelpers.CheckOneMultiError(t, err, "Unknown healthcheck type 'notping' in foo")
}
Example #10
0
func TestManageRoutesSpecValidateBadCidr3(t *testing.T) {
	r := ManageRoutesSpec{
		Cidr:     "foo",
		Instance: "SELF",
	}
	err := r.Validate(im1, &FakeRouteTableManager{}, "bar", emptyHealthchecks, emptyHealthchecks)
	testhelpers.CheckOneMultiError(t, err, "Could not parse invalid CIDR address: foo/32 in bar")
}
Example #11
0
func TestManageRoutesSpecValidateMissingRemoteHealthcheck(t *testing.T) {
	r := ManageRoutesSpec{
		Cidr:                  "0.0.0.0/0",
		Instance:              "SELF",
		RemoteHealthcheckName: "test",
	}
	err := r.Validate(im1, &FakeRouteTableManager{}, "foo", emptyHealthchecks, emptyHealthchecks)
	testhelpers.CheckOneMultiError(t, err, "Route tables foo, route 0.0.0.0/0 cannot find remote healthcheck 'test'")
}
Example #12
0
func TestUpdateRemoteHealthchecksEmpty(t *testing.T) {
	rs := &ManageRoutesSpec{
		Cidr: "127.0.0.1",
		RemoteHealthcheckName: "test",
	}
	err := rs.Validate(im1, &FakeRouteTableManager{}, "foo", emptyHealthchecks, emptyHealthchecks)
	testhelpers.CheckOneMultiError(t, err, "Route tables foo, route 127.0.0.1/32 cannot find remote healthcheck 'test'")
	rs.UpdateRemoteHealthchecks()
}
Example #13
0
func TestRouteTableFindSpecValidateNoType(t *testing.T) {
	c := make(map[string]interface{})
	c["key"] = "Name"
	c["value"] = "private a"
	r := RouteTableFindSpec{
		Config: c,
	}
	err := r.Validate("foo")
	testhelpers.CheckOneMultiError(t, err, "Route find spec foo needs a type key")
}
Example #14
0
func TestByTagRouteTableFindMissingValue(t *testing.T) {
	c := make(map[string]interface{})
	c["key"] = "Name"
	rts := RouteTableFindSpec{
		Type:   "by_tag",
		Config: c,
	}
	rtf, err := rts.GetFilter()
	assert.Nil(t, rtf)
	testhelpers.CheckOneMultiError(t, err, "No value in config for by_tag route table finder")
}
Example #15
0
func TestRouteTableFindSpecValidateUnknownType(t *testing.T) {
	c := make(map[string]interface{})
	c["key"] = "Name"
	c["value"] = "private a"
	r := RouteTableFindSpec{
		Type:   "doesnotexist",
		Config: c,
	}
	err := r.Validate("foo")
	testhelpers.CheckOneMultiError(t, err, "Route find spec foo type 'doesnotexist' not known")
}
Example #16
0
func TestConfigValidateBadHealthChecks(t *testing.T) {
	c_disk, _ := New("../tests/awsnycast.yaml", tim, rtm)
	c := Config{
		RouteTables:  c_disk.RouteTables,
		Healthchecks: c_disk.Healthchecks,
	}
	c.Healthchecks["foo"] = &healthcheck.Healthcheck{Type: "tcp"}
	c.Healthchecks["foo"].Validate("foo", false)
	err := c.Validate(tim, rtm)
	testhelpers.CheckOneMultiError(t, err, "Healthcheck foo has no destination set")
}
Example #17
0
func TestHealthcheckTcpNoPort(t *testing.T) {
	c := make(map[string]interface{})
	c["send"] = "HEAD / HTTP/1.0\r\n\r\n"
	c["expect"] = "200 OK"
	h := Healthcheck{
		Type:        "tcp",
		Destination: "127.0.0.1",
		Config:      c,
	}
	h.Validate("foo", false)
	err := h.Setup()
	if assert.NotNil(t, err) {
		testhelpers.CheckOneMultiError(t, err, "'port' not defined in tcp healthcheck config to 127.0.0.1")
	}
}
Example #18
0
func TestRouteTableValidateNoRoutes(t *testing.T) {
	c := make(map[string]interface{})
	c["key"] = "Name"
	c["value"] = "private a"
	rfs := RouteTableFindSpec{
		Type:   "by_tag",
		Config: c,
	}
	r := RouteTable{
		Find:         rfs,
		ManageRoutes: make([]*aws.ManageRoutesSpec, 0),
	}
	err := r.Validate(tim, rtm, "foo", emptyHealthchecks, emptyHealthchecks)
	testhelpers.CheckOneMultiError(t, err, "No manage_routes key in route table 'foo'")
}
Example #19
0
func TestConfigValidateBadRouteTables(t *testing.T) {
	r := make(map[string]*RouteTable)
	conf := make(map[string]interface{})
	conf["key"] = "foo"
	conf["value"] = "foo"
	r["foo"] = &RouteTable{
		Find: RouteTableFindSpec{
			Type:   "by_tag",
			Config: conf,
		},
	}
	c := Config{
		RouteTables: r,
	}
	err := c.Validate(tim, rtm)
	testhelpers.CheckOneMultiError(t, err, "No manage_routes key in route table 'foo'")
}
Example #20
0
func TestConfigValidateBadRouteTableUpserts(t *testing.T) {
	r := make(map[string]*RouteTable)
	urs := make([]*aws.ManageRoutesSpec, 1)
	c := make(map[string]interface{})
	c["key"] = "foo"
	c["value"] = "bar"
	urs[0] = &aws.ManageRoutesSpec{}
	r["foo"] = &RouteTable{
		Find: RouteTableFindSpec{
			Type:   "by_tag",
			Config: c,
		},
		ManageRoutes: urs,
	}
	conf := Config{
		RouteTables: r,
	}
	err := conf.Validate(tim, rtm)
	testhelpers.CheckOneMultiError(t, err, "cidr is not defined in foo")
}
Example #21
0
func TestRouteTableFindSpecOrNoFilters(t *testing.T) {
	c := make(map[string]interface{})
	_, err := RouteTableFindSpec{Config: c, Type: "or"}.GetFilter()
	testhelpers.CheckOneMultiError(t, err, "No filters in config for or route table finder")
}
Example #22
0
func TestLoadConfigFailsValidation(t *testing.T) {
	_, err := New("../tests/invalid.yaml", tim, rtm)
	testhelpers.CheckOneMultiError(t, err, "Route tables a, route 0.0.0.0/0 cannot find healthcheck 'public'")
}
Example #23
0
func TestConfigValidateEmpty(t *testing.T) {
	c := Config{}
	err := c.Validate(tim, rtm)
	testhelpers.CheckOneMultiError(t, err, "No route_tables key in config")
}