Beispiel #1
0
func TestDelete(t *testing.T) {
	if err := etcdtest.DeleteAll(); err != nil {
		t.Error(err)
		return
	}
	c, err := New(Options{etcdtest.Urls, "/skippertest", 0, false})
	if err != nil {
		t.Error(err)
		return
	}

	err = c.Upsert(&eskip.Route{
		Id:     "route1",
		Method: "POST",
		Shunt:  true})
	if err != nil {
		t.Error(err)
	}

	err = c.Delete("route1")
	if err != nil {
		t.Error(err)
	}

	routes, err := c.LoadAll()
	if len(routes) != 0 {
		t.Error("failed to delete route")
	}
}
Beispiel #2
0
func TestDeleteNotExists(t *testing.T) {
	if err := etcdtest.DeleteAll(); err != nil {
		t.Error(err)
		return
	}
	c, err := New(Options{etcdtest.Urls, "/skippertest", 0, false})
	if err != nil {
		t.Error(err)
		return
	}

	err = c.Upsert(&eskip.Route{
		Id:     "route1",
		Method: "POST",
		Shunt:  true})
	if err != nil {
		t.Error(err)
	}

	err = c.Delete("route1")
	if err != nil {
		t.Error(err)
	}

	err = c.Delete("route1")
	if err != nil {
		t.Error(err)
	}
}
Beispiel #3
0
func TestUpsertNew(t *testing.T) {
	if err := etcdtest.DeleteAll(); err != nil {
		t.Error(err)
		return
	}

	c, err := New(Options{etcdtest.Urls, "/skippertest", 0, false})
	if err != nil {
		t.Error(err)
		return
	}

	err = c.Upsert(&eskip.Route{
		Id:     "route1",
		Method: "POST",
		Shunt:  true})
	if err != nil {
		t.Error(err)
	}

	routes, err := c.LoadAll()
	if len(routes) != 1 || routes[0].Id != "route1" {
		t.Error("failed to upsert route", len(routes))
	}
}
Beispiel #4
0
func TestCheckEtcd(t *testing.T) {
	urls, err := stringsToUrls(etcdtest.Urls...)
	if err != nil {
		t.Error(err)
	}

	etcdtest.DeleteAll()
	etcdtest.PutData("route1", `Method("POST") -> <shunt>`)
	if err != nil {
		t.Error(err)
	}

	err = checkCmd(cmdArgs{in: &medium{typ: etcd, urls: urls, path: "/skippertest"}})
	if err != nil {
		t.Error(err)
	}
}
Beispiel #5
0
func TestCheckEtcdInvalid(t *testing.T) {
	urls, err := stringsToUrls(etcdtest.Urls...)
	if err != nil {
		t.Error(err)
	}

	etcdtest.DeleteAll()
	etcdtest.PutData("route1", "invalid doc")
	if err != nil {
		t.Error(err)
	}

	err = checkCmd(cmdArgs{in: &medium{typ: etcd, urls: urls, path: "/skippertest"}})
	if err != invalidRouteExpression {
		t.Error("failed to fail properly")
	}
}
Beispiel #6
0
func TestCheckEtcd(t *testing.T) {
	urls, err := stringsToUrls(etcdtest.Urls...)
	if err != nil {
		t.Error(err)
	}

	etcdtest.DeleteAll()
	etcdtest.PutData("route1", `Method("POST") -> <shunt>`)
	if err != nil {
		t.Error(err)
	}

	readClient, _ := createReadClient(&medium{typ: etcd, urls: urls, path: "/skippertest"})

	err = checkCmd(readClient, nil, nil)
	if err != nil {
		t.Error(err)
	}
}
Beispiel #7
0
func TestLoadWithParseFailures(t *testing.T) {
	if err := etcdtest.DeleteAll(); err != nil {
		t.Error(err)
		return
	}

	etcdtest.PutData("catalog", `Path("/pdp") -> "https://catalog.example.org"`)
	etcdtest.PutData("cms", "invalid expression")

	c, err := New(Options{etcdtest.Urls, "/skippertest", 0, false})
	if err != nil {
		t.Error(err)
		return
	}

	routeInfo, err := c.LoadAndParseAll()
	if err != nil {
		t.Error(err)
	}

	if len(routeInfo) != 2 {
		t.Error("failed to load all routes", len(routeInfo))
	}

	var parseError error
	for _, ri := range routeInfo {
		if ri.ParseError != nil {
			if parseError != nil {
				t.Error("too many errors")
			}

			parseError = ri.ParseError
		}
	}

	if parseError == nil {
		t.Error("failed to detect parse error")
	}
}