Ejemplo n.º 1
0
func TestDeleteRoute(t *testing.T) {
	resetData(t)
	c := etcd.NewClient(mock.EtcdUrls)
	dc, _ := Make(mock.EtcdUrls, "/skippertest")

	if !waitForEtcd(dc, checkInitial) {
		t.Error("failed to get initial data")
	}

	_, err := c.Delete("/skippertest/routes/pdp", false)
	if err != nil {
		t.Error("failed to delete route")
	}

	if !waitForEtcd(dc, func(rd skipper.RawData) bool {
		d, err := eskip.Parse(rd.Get())
		if err != nil {
			return false
		}

		return len(d) == 0
	}) {
		t.Error("failed to delete route")
	}
}
Ejemplo n.º 2
0
func checkInitial(rd skipper.RawData) bool {
	d, err := eskip.Parse(rd.Get())
	if err != nil {
		return false
	}

	if len(d) != 1 {
		return false
	}

	r := d[0]

	if r.Id != "pdp" {
		return false
	}

	if r.MatchExp != "PathRegexp(`.*\\.html`)" {
		return false
	}

	if len(r.Filters) != 2 {
		return false
	}

	checkFilter := func(f *eskip.Filter, name string, args ...interface{}) bool {
		if f.Name != name {
			return false
		}

		if len(f.Args) != len(args) {
			return false
		}

		for i, a := range args {
			if f.Args[i] != a {
				return false
			}
		}

		return true
	}

	if !checkFilter(r.Filters[0], "customHeader", 3.14) {
		return false
	}

	if !checkFilter(r.Filters[1], "xSessionId", "v4") {
		return false
	}

	if r.Backend != "https://www.zalando.de" {
		return false
	}

	return true
}
Ejemplo n.º 3
0
func checkBackend(rd skipper.RawData, routeId, backend string) bool {
	d, err := eskip.Parse(rd.Get())
	if err != nil {
		return false
	}

	for _, r := range d {
		if r.Id == routeId {
			return r.Backend == backend
		}
	}

	return false
}
Ejemplo n.º 4
0
func TestInsertUpdateDelete(t *testing.T) {
	resetData(t)
	c := etcd.NewClient(mock.EtcdUrls)
	dc, _ := Make(mock.EtcdUrls, "/skippertest")

	if !waitForEtcd(dc, checkInitial) {
		t.Error("faield to get initial data")
	}

	c.Set("/skippertest/routes/pdp1", `Path("/pdp1") -> "http://www.zalando.de/pdp-inserted-1.html"`, 0)
	c.Set("/skippertest/routes/pdp2", `Path("/pdp2") -> "http://www.zalando.de/pdp-inserted-2.html"`, 0)
	c.Delete("/skippertest/routes/pdp1", false)
	c.Set("/skippertest/routes/pdp2", `Path("/pdp2") -> "http://www.zalando.de/pdp-mod-2.html"`, 0)

	if !waitForEtcd(dc, func(rd skipper.RawData) bool {
		d, err := eskip.Parse(rd.Get())
		if err != nil {
			return false
		}

		if len(d) != 2 {
			return false
		}

		var originalOk, modOk bool
		for _, r := range d {
			if r.Id == "pdp" && r.Backend == "https://www.zalando.de" {
				originalOk = true
			}

			if r.Id == "pdp2" && r.Backend == "http://www.zalando.de/pdp-mod-2.html" {
				modOk = true
			}
		}

		return originalOk && modOk
	}) {
		t.Error("failed to delete route")
	}
}