Exemplo n.º 1
0
func SetRoute(route core.Route) error {
	// in case of failure
	oldRoutes, err := database.GetRoutes()
	if err != nil {
		return err
	}

	// apply to proxymgr
	err = proxymgr.SetRoute(route)
	if err != nil {
		return err
	}

	if !database.CentralStore {
		// save to backend
		err = database.SetRoute(route)
		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
}
Exemplo n.º 2
0
////////////////////////////////////////////////////////////////////////////////
// ROUTES
////////////////////////////////////////////////////////////////////////////////
func TestSetRoute(t *testing.T) {
	if err := proxymgr.SetRoute(testRoute); err != nil {
		t.Errorf("Failed to SET route - %v", err)
		t.FailNow()
	}

	// test idempotency
	if err := proxymgr.SetRoute(testRoute); err != nil {
		t.Errorf("Failed to SET route - %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")
	}
}