func TestDeleteFromRoutes(t *testing.T) { etcdtest.DeleteAllFrom(defaultEtcdPrefix) in := &medium{typ: inline, eskip: `route1: Method("POST") -> <shunt>`} out := &medium{typ: etcd, urls: testEtcdUrls, path: defaultEtcdPrefix} err := upsertCmd(cmdArgs{in: in, out: out}) if err != nil { t.Error(err) } in = &medium{typ: inline, eskip: `route1: Method("HEAD") -> <shunt>;route2: Method("PUT") -> <shunt>`} err = deleteCmd(cmdArgs{in: in, out: out}) if err != nil { t.Error(err) } routes, err := loadRoutesChecked(out) if err != nil { t.Error(err) } if len(routes) != 0 { t.Error("delete failed") } }
func TestResetLoadExistingFails(t *testing.T) { etcdtest.DeleteAllFrom(defaultEtcdPrefix) in := &medium{typ: inline, eskip: `route2: Method("POST") -> <shunt>`} out := &medium{typ: etcd, urls: testEtcdUrls, path: defaultEtcdPrefix} err := etcdtest.PutDataTo(defaultEtcdPrefix, "route1", "invalid doc") if err != nil { t.Error(err) } err = resetCmd(cmdArgs{in: in, out: out}) if err != nil { t.Error(err) } _, err = etcdtest.GetNodeFrom(defaultEtcdPrefix, "route1") if err == nil { t.Error(err) } _, err = etcdtest.GetNodeFrom(defaultEtcdPrefix, "route2") if err != nil { t.Error(err) } }
func TestDeleteFromRoutes(t *testing.T) { etcdtest.DeleteAllFrom(defaultEtcdPrefix) in := &medium{typ: inline, eskip: `route1: Method("POST") -> <shunt>`} out := &medium{typ: etcd, urls: testEtcdUrls, path: defaultEtcdPrefix} writeClient, _ := createWriteClient(out) readOutClient, _ := createReadClient(out) readClient, _ := createReadClient(in) err := upsertCmd(readClient, readOutClient, writeClient) if err != nil { t.Error(err) } in = &medium{typ: inline, eskip: `route1: Method("HEAD") -> <shunt>;route2: Method("PUT") -> <shunt>`} err = deleteCmd(readClient, readOutClient, writeClient) if err != nil { t.Error(err) } routes, err := loadRoutesChecked(readOutClient) if err != nil { t.Error(err) } if len(routes) != 0 { t.Error("delete failed") } }
func TestResetLoadExistingFails(t *testing.T) { etcdtest.DeleteAllFrom(defaultEtcdPrefix) in := &medium{typ: inline, eskip: `route2: Method("POST") -> <shunt>`} out := &medium{typ: etcd, urls: testEtcdUrls, path: defaultEtcdPrefix} writeClient, _ := createWriteClient(out) readOutClient, _ := createReadClient(out) readClient, _ := createReadClient(in) err := etcdtest.PutDataTo(defaultEtcdPrefix, "route1", "invalid doc") if err != nil { t.Error(err) } err = resetCmd(readClient, readOutClient, writeClient) if err != nil { t.Error(err) } _, err = etcdtest.GetNodeFrom(defaultEtcdPrefix, "route1") if err == nil { t.Error(err) } _, err = etcdtest.GetNodeFrom(defaultEtcdPrefix, "route2") if err != nil { t.Error(err) } }
func TestReset(t *testing.T) { etcdtest.DeleteAllFrom(defaultEtcdPrefix) in := &medium{typ: inline, eskip: `route2: Method("PUT") -> <shunt>; route3: Method("HEAD") -> <shunt>`} out := &medium{typ: etcd, urls: testEtcdUrls, path: defaultEtcdPrefix} writeClient, _ := createWriteClient(out) readOutClient, _ := createReadClient(out) readClient, _ := createReadClient(in) err := etcdtest.PutDataTo(defaultEtcdPrefix, "route1", `Method("GET") -> <shunt>`) if err != nil { t.Error(err) } err = etcdtest.PutDataTo(defaultEtcdPrefix, "route2", `Method("POST") -> <shunt>`) if err != nil { t.Error(err) } err = resetCmd(readClient, readOutClient, writeClient) if err != nil { t.Error(err) } routes, err := loadRoutesChecked(readOutClient) if err != nil { t.Error(err) } if len(routes) != 2 { t.Error("failed to reset routes") } for _, id := range []string{"route2", "route3"} { found := false for _, r := range routes { if r.Id != id { continue } found = true switch id { case "route2": if r.Method != "PUT" { t.Error("failed to reset routes") } case "route3": if r.Method != "HEAD" { t.Error("failed to reset routes") } } } if !found { t.Error("failed to reset routes") } } }
func TestUpsertUsesId(t *testing.T) { etcdtest.DeleteAllFrom(defaultEtcdPrefix) in := &medium{typ: inline, eskip: `route1: Method("POST") -> <shunt>`} out := &medium{typ: etcd, urls: testEtcdUrls, path: defaultEtcdPrefix} err := upsertCmd(cmdArgs{in: in, out: out}) if err != nil { t.Error(err) } routes, err := loadRoutesChecked(out) if err != nil { t.Error(err) } if len(routes) != 1 || routes[0].Id != "route1" { t.Error("upsert failed") } }
func TestUpsertUsesId(t *testing.T) { etcdtest.DeleteAllFrom(defaultEtcdPrefix) in := &medium{typ: inline, eskip: `route1: Method("POST") -> <shunt>`} out := &medium{typ: etcd, urls: testEtcdUrls, path: defaultEtcdPrefix} writeClient, _ := createWriteClient(out) readOutClient, _ := createReadClient(out) readClient, _ := createReadClient(in) err := upsertCmd(readClient, readOutClient, writeClient) if err != nil { t.Error(err) } routes, err := loadRoutesChecked(readOutClient) if err != nil { t.Error(err) } if len(routes) != 1 || routes[0].Id != "route1" { t.Error("upsert failed") } }