Ejemplo n.º 1
0
func (b *FusisBalancer) AddCheck(check types.CheckSpec) error {
	// Setting default values
	if check.Timeout == 0 {
		check.Timeout = 5 * time.Second
	}

	if check.Interval == 0 {
		check.Interval = 10 * time.Second
	}

	return b.store.AddCheck(check)
}
Ejemplo n.º 2
0
func (as ApiService) addCheck(c echo.Context) error {
	var check types.CheckSpec
	if err := c.Bind(&check); err != nil {
		return err
	}

	check.ServiceID = c.Param("service_name")

	// Converting int to time.Duration
	check.Interval = check.Interval * time.Second
	check.Timeout = check.Timeout * time.Second

	if err := as.balancer.AddCheck(check); err != nil {
		return err
	}

	return c.JSON(http.StatusCreated, check)
}
Ejemplo n.º 3
0
func (s *ApiTestSuite) TestAddCheck() {
	spec := types.CheckSpec{ServiceID: s.service.Name, Interval: 5 * time.Second, Timeout: 5 * time.Second}
	s.balancer.On("AddCheck", spec).Return(nil)

	spec.ServiceID = s.service.GetId()
	expectedBody, err := json.Marshal(spec)
	assert.Nil(s.T(), err)

	s.r.POST("/services/"+s.service.Name+"/check").
		SetJSON(gofight.D{
			"interval": 5,
			"timeout":  5,
		}).
		Run(s.api.echo, func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
			s.balancer.AssertExpectations(s.T())

			assert.Equal(s.T(), http.StatusCreated, r.Code)
			assert.Equal(s.T(), string(expectedBody), r.Body.String())
		})
}