Skip to content

Commit

Permalink
refactor(api.mock): simplify Request and Do
Browse files Browse the repository at this point in the history
  • Loading branch information
nobe4 committed Jun 22, 2024
1 parent caacb22 commit 8e5a9c1
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions internal/api/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,39 @@ func (e *MockError) Error() string {
}

func New(c []Call) (api.Caller, error) {

Check failure on line 35 in internal/api/mock/mock.go

View workflow job for this annotation

GitHub Actions / deadcode

unreachable func: New
return &Mock{
Calls: c,
index: 0,
}, nil
return &Mock{Calls: c}, nil
}

func (m *Mock) Do(verb, endpoint string, body io.Reader, out interface{}) error {
func (m *Mock) call(verb, endpoint string) (Call, error) {

Check failure on line 39 in internal/api/mock/mock.go

View workflow job for this annotation

GitHub Actions / deadcode

unreachable func: Mock.call
if m.index >= len(m.Calls) {
return &MockError{verb, endpoint, "no more calls"}
return Call{}, &MockError{verb, endpoint, "no more calls"}
}

call := m.Calls[m.index]
if (call.Verb != "" && call.Verb != verb) || (call.Endpoint != "" && call.Endpoint != endpoint) {
return &MockError{verb, endpoint, "unexpected call"}
return Call{}, &MockError{verb, endpoint, "unexpected call"}
}

m.index++

return call, nil
}

func (m *Mock) Do(verb, endpoint string, body io.Reader, out interface{}) error {

Check failure on line 54 in internal/api/mock/mock.go

View workflow job for this annotation

GitHub Actions / deadcode

unreachable func: Mock.Do
call, err := m.call(verb, endpoint)
if err != nil {
return err
}

out = call.Data
return call.Error
}

func (m *Mock) Request(verb, endpoint string, body io.Reader) (*http.Response, error) {

Check failure on line 64 in internal/api/mock/mock.go

View workflow job for this annotation

GitHub Actions / deadcode

unreachable func: Mock.Request
if m.index >= len(m.Calls) {
return nil, &MockError{verb, endpoint, "no more calls"}
call, err := m.call(verb, endpoint)
if err != nil {
return nil, err
}

call := m.Calls[m.index]
if (call.Verb != "" && call.Verb != verb) || (call.Endpoint != "" && call.Endpoint != endpoint) {
return nil, &MockError{verb, endpoint, "unexpected call"}
}

m.index++

return call.Response, call.Error
}

0 comments on commit 8e5a9c1

Please sign in to comment.