diff --git a/broker/broker_test.go b/broker/broker_test.go index cb88453..9a5c8e3 100644 --- a/broker/broker_test.go +++ b/broker/broker_test.go @@ -15,6 +15,7 @@ import ( func TestBrokerInterface(t *testing.T) { var b Broker + b = FastExact{} b = NTGVision{} _ = b } diff --git a/broker/fastexact.go b/broker/fastexact.go new file mode 100644 index 0000000..7ef26ea --- /dev/null +++ b/broker/fastexact.go @@ -0,0 +1,69 @@ +package broker + +import ( + "errors" + "local/truckstop/config" + "net/http" +) + +type FastExact struct { + doer interface { + doRequest(*http.Request) (*http.Response, error) + } +} + +func NewFastExact() FastExact { + fe := FastExact{} + fe.doer = fe + return fe +} + +func (fe FastExact) WithMock() FastExact { + fe.doer = mockFastExactDoer{} + return fe +} + +func (fe FastExact) Search(states []config.State) ([]Job, error) { + jobs, err := fe.search(states) + if err == ErrNoAuth { + if err := fe.login(); err != nil { + return nil, err + } + jobs, err = fe.search(states) + } + return jobs, err +} + +func (fe FastExact) login() error { + return errors.New("not impl") +} + +func (fe FastExact) search(states []config.State) ([]Job, error) { + req, err := fe.newRequest(states) + if err != nil { + return nil, err + } + resp, err := fe.doRequest(req) + if err != nil { + return nil, err + } + return fe.parse(resp) +} + +func (fe FastExact) newRequest(states []config.State) (*http.Request, error) { + return nil, errors.New("not impl") +} + +func (fe FastExact) doRequest(req *http.Request) (*http.Response, error) { + return nil, errors.New("not impl") +} + +func (fe FastExact) parse(resp *http.Response) ([]Job, error) { + return nil, errors.New("not impl") +} + +type mockFastExactDoer struct{} + +func (mock mockFastExactDoer) doRequest(*http.Request) (*http.Response, error) { + return nil, errors.New("not impl") +}