2022-06-09 20:12:45 +00:00
|
|
|
package http
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
2022-08-02 18:45:09 +00:00
|
|
|
"code.1533b4dc0.de/prskr/nurse/grammar"
|
|
|
|
"code.1533b4dc0.de/prskr/nurse/validation"
|
2022-06-09 20:12:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var _ validation.FromCall[*http.Response] = (*StatusValidator)(nil)
|
|
|
|
|
|
|
|
type StatusValidator struct {
|
|
|
|
Want int
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StatusValidator) Validate(resp *http.Response) error {
|
|
|
|
if resp.StatusCode != s.Want {
|
|
|
|
return fmt.Errorf("want HTTP status %d but got %d", s.Want, resp.StatusCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StatusValidator) UnmarshalCall(c grammar.Call) error {
|
|
|
|
if err := grammar.ValidateParameterCount(c.Params, 1); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
|
|
|
s.Want, err = c.Params[0].AsInt()
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|