master
Bel LaPointe 2022-01-27 13:02:48 -07:00
parent 16bf70a276
commit 34fc5fbc5c
2 changed files with 70 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import (
func TestBrokerInterface(t *testing.T) { func TestBrokerInterface(t *testing.T) {
var b Broker var b Broker
b = FastExact{}
b = NTGVision{} b = NTGVision{}
_ = b _ = b
} }

69
broker/fastexact.go Normal file
View File

@ -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")
}