func SetRoutes(routes []core.Route) error { // in case of failure oldRoutes, err := database.GetRoutes() if err != nil { return err } // apply routes to proxymgr err = proxymgr.SetRoutes(routes) if err != nil { return err } if !database.CentralStore { // save to backend err = database.SetRoutes(routes) if err != nil { // undo proxymgr action if uerr := proxymgr.SetRoutes(oldRoutes); uerr != nil { err = fmt.Errorf("%v - %v", err.Error(), uerr.Error()) } return err } } return nil }
func TestSetRoutes(t *testing.T) { if err := proxymgr.SetRoutes([]core.Route{testRoute}); err != nil { t.Errorf("Failed to SET routes - %v", err) t.FailNow() } routes, err := proxymgr.GetRoutes() if err != nil { t.Error(err) } if len(routes) == 1 && routes[0].Domain != testRoute.Domain { t.Errorf("Read route differs from written route") } }