Пример #1
0
func (e *Command) test(cmd *cobra.Command, args []string) {
	fmt.Println("Router testing.")
	frontendname := "geard-router-test"
	alias := "www.alias.com"
	router.CreateFrontend(frontendname, alias)

	// empty the global datastucture and re-read to confirm that correct output has been generated
	router.GlobalRoutes = nil
	router.ReadRoutes()
	frontend, ok := router.GlobalRoutes[frontendname]
	if !ok {
		fmt.Println("Test failed. Frontend created was not persisted.")
		return
	}
	if frontend.HostAliases[0] != alias {
		fmt.Println("Test failed. Frontend created did not persist its alias.")
		return
	}

	// create a route
	s := router.Endpoint{}
	s.IP = "localhost"
	s.Port = "4001"
	endpoints := make([]router.Endpoint, 1)
	endpoints[0] = s
	router.AddRoute(frontendname, "", "", nil, endpoints)

	// empty the db again and check for routes
	router.GlobalRoutes = nil
	router.ReadRoutes()
	frontend, ok = router.GlobalRoutes[frontendname]
	if !ok {
		fmt.Println("Test failed. Frontend created was not persisted.")
		return
	}
	if len(frontend.EndpointTable) != 1 {
		fmt.Println("Test failed. Created one route, but %d found.", len(frontend.EndpointTable))
		return
	}
	for _, ep := range frontend.EndpointTable {
		if ep.IP != "localhost" || ep.Port != "4001" {
			fmt.Println("Test failed. Created one route, but invalid values were persisted.", len(frontend.EndpointTable))
			return
		}
	}

	// good so far, now delete the testfrontend
	router.DeleteFrontend(frontendname)
	_, ok = router.GlobalRoutes[frontendname]
	if ok {
		fmt.Println("Test failed. Frontend deletion does not actually remove the frontend from the routing table.")
	}

	// all good
	fmt.Println(router.PrintRoutes())
}
Пример #2
0
func (j AddRouteRequest) Execute(resp jobs.Response) {
	router.AddRoute(j.Frontend, j.FrontendPath, j.BackendPath, j.Protocols, j.Endpoints)
	resp.Success(jobs.ResponseOk)
}