-
Notifications
You must be signed in to change notification settings - Fork 4
/
bbclientmock.go
40 lines (34 loc) · 1.1 KB
/
bbclientmock.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package bbclientmock
import (
"context"
"errors"
"github.com/Interhyp/metadata-service/internal/acorn/errors/httperror"
"github.com/Interhyp/metadata-service/internal/acorn/repository"
"strings"
)
const NOT_EXISITNG_USER = "notexistinguser"
const HTTP_ERROR_USER = "httperroruser"
const OTHER_ERROR_USER = "othererroruser"
func MockBitbucketUser() repository.BitbucketUser {
return repository.BitbucketUser{
Id: 1234,
Name: "mock-user",
}
}
type BitbucketClientMock struct {
}
func (m *BitbucketClientMock) GetBitbucketUser(ctx context.Context, username string) (repository.BitbucketUser, error) {
if strings.EqualFold(username, NOT_EXISITNG_USER) {
return repository.BitbucketUser{}, httperror.New(context.Background(), "not-found", 404)
}
if strings.EqualFold(username, HTTP_ERROR_USER) {
return repository.BitbucketUser{}, httperror.New(context.Background(), "http-error", 502)
}
if strings.EqualFold(username, OTHER_ERROR_USER) {
return repository.BitbucketUser{}, errors.New("some-error")
}
return MockBitbucketUser(), nil
}
func (m *BitbucketClientMock) Setup() error {
return nil
}