Example #1
0
func validateTcpRouteMapping(tcpRouteMapping db.TcpRouteMapping) *routing_api.Error {
	if tcpRouteMapping.TcpRoute.RouterGroupGuid == "" {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp mapping requires a non empty router group guid. RouteMapping=["+tcpRouteMapping.String()+"]")
		return &err
	}

	if tcpRouteMapping.TcpRoute.ExternalPort <= 0 {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp mapping requires a positive external port. RouteMapping=["+tcpRouteMapping.String()+"]")
		return &err
	}

	if tcpRouteMapping.HostIP == "" {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp mapping requires a non empty backend ip. RouteMapping=["+tcpRouteMapping.String()+"]")
		return &err
	}

	if tcpRouteMapping.HostPort <= 0 {
		err := routing_api.NewError(routing_api.TcpRouteMappingInvalidError,
			"Each tcp mapping requires a positive backend port. RouteMapping=["+tcpRouteMapping.String()+"]")
		return &err
	}

	return nil
}
Example #2
0
				Expect(err.Error()).To(Equal("Each route request requires a port greater than 0"))
			})

			It("returns an error if any request does not have an IP", func() {
				routes[1].IP = ""

				err := validator.ValidateDelete(routes)
				Expect(err.Type).To(Equal(routing_api.RouteInvalidError))
				Expect(err.Error()).To(Equal("Each route request requires an IP"))
			})
		})
	})

	Describe("ValidateTcpRouteMapping", func() {
		var (
			tcpMapping db.TcpRouteMapping
		)

		BeforeEach(func() {
			tcpMapping = db.NewTcpRouteMapping("router-group-guid-001", 52000, "1.2.3.4", 60000)
		})

		Context("when valid tcp mapping is passed", func() {
			It("does not return error", func() {
				err := validator.ValidateTcpRouteMapping([]db.TcpRouteMapping{tcpMapping})
				Expect(err).To(BeNil())
			})
		})

		Context("when invalid tcp route mappings are passed", func() {