Perform a few renamings

This commit is contained in:
Jan-Eric Hellenberg
2021-05-11 10:38:01 +02:00
parent 54df1e8ec8
commit fde334a610
7 changed files with 23 additions and 25 deletions

View File

@ -50,8 +50,8 @@ test:
needs: []
script:
- go test $(go list ./... | grep -v /e2e_tests) -v -coverprofile coverage.cov
- # exclude Mock files from coverage report
- cat coverage.cov | grep -v Mock.go > coverage_cleaned.cov || true
# exclude Mock files from coverage report
- cat coverage.cov | grep -v _mock.go > coverage_cleaned.cov || true
- go tool cover -func=coverage_cleaned.cov
- go tool cover -html=coverage_cleaned.cov -o coverage_unit.html
artifacts:

View File

@ -69,7 +69,7 @@ func main() {
logging.InitializeLogging(config.Config.Logger.Level)
// API initialization
nomadAPIClient, err := nomad.New(config.Config.NomadAPIURL())
nomadAPIClient, err := nomad.NewExecutorApi(config.Config.NomadAPIURL())
if err != nil {
log.WithError(err).WithField("nomad url", config.Config.NomadAPIURL()).Fatal("Error parsing the nomad url")
}

View File

@ -5,8 +5,8 @@ import (
"net/url"
)
// nomadApiQuerier provides access to the Nomad functionality.
type nomadApiQuerier interface {
// apiQuerier provides access to the Nomad functionality.
type apiQuerier interface {
// init prepares an apiClient to be able to communicate to a provided Nomad API.
init(nomadURL *url.URL) (err error)

View File

@ -9,13 +9,13 @@ import (
url "net/url"
)
// nomadApiQuerierMock is an autogenerated mock type for the nomadApiQuerier type
type nomadApiQuerierMock struct {
// apiQuerierMock is an autogenerated mock type for the apiQuerier type
type apiQuerierMock struct {
mock.Mock
}
// DeleteRunner provides a mock function with given fields: runnerId
func (_m *nomadApiQuerierMock) DeleteRunner(runnerId string) error {
func (_m *apiQuerierMock) DeleteRunner(runnerId string) error {
ret := _m.Called(runnerId)
var r0 error
@ -29,7 +29,7 @@ func (_m *nomadApiQuerierMock) DeleteRunner(runnerId string) error {
}
// GetJobScale provides a mock function with given fields: jobId
func (_m *nomadApiQuerierMock) GetJobScale(jobId string) (int, error) {
func (_m *apiQuerierMock) GetJobScale(jobId string) (int, error) {
ret := _m.Called(jobId)
var r0 int
@ -50,7 +50,7 @@ func (_m *nomadApiQuerierMock) GetJobScale(jobId string) (int, error) {
}
// LoadJobList provides a mock function with given fields:
func (_m *nomadApiQuerierMock) LoadJobList() ([]*api.JobListStub, error) {
func (_m *apiQuerierMock) LoadJobList() ([]*api.JobListStub, error) {
ret := _m.Called()
var r0 []*api.JobListStub
@ -73,7 +73,7 @@ func (_m *nomadApiQuerierMock) LoadJobList() ([]*api.JobListStub, error) {
}
// SetJobScaling provides a mock function with given fields: jobId, count, reason
func (_m *nomadApiQuerierMock) SetJobScaling(jobId string, count int, reason string) error {
func (_m *apiQuerierMock) SetJobScaling(jobId string, count int, reason string) error {
ret := _m.Called(jobId, count, reason)
var r0 error
@ -87,7 +87,7 @@ func (_m *nomadApiQuerierMock) SetJobScaling(jobId string, count int, reason str
}
// init provides a mock function with given fields: nomadURL
func (_m *nomadApiQuerierMock) init(nomadURL *url.URL) error {
func (_m *apiQuerierMock) init(nomadURL *url.URL) error {
ret := _m.Called(nomadURL)
var r0 error
@ -101,7 +101,7 @@ func (_m *nomadApiQuerierMock) init(nomadURL *url.URL) error {
}
// loadRunners provides a mock function with given fields: jobId
func (_m *nomadApiQuerierMock) loadRunners(jobId string) ([]*api.AllocationListStub, error) {
func (_m *apiQuerierMock) loadRunners(jobId string) ([]*api.AllocationListStub, error) {
ret := _m.Called(jobId)
var r0 []*api.AllocationListStub

View File

@ -5,9 +5,9 @@ import (
"net/url"
)
// ExecutorApi provides access to an container orchestration solution
// ExecutorApi provides access to a container orchestration solution.
type ExecutorApi interface {
nomadApiQuerier
apiQuerier
// LoadAvailableRunners loads all allocations of the specified job which are running and not about to get stopped.
LoadAvailableRunners(jobId string) (runnerIds []string, err error)
@ -15,15 +15,13 @@ type ExecutorApi interface {
// ApiClient implements the ExecutorApi interface and can be used to perform different operations on the real Executor API and its return values.
type ApiClient struct {
nomadApiQuerier
apiQuerier
}
// New creates a new api client.
// NewExecutorApi creates a new api client.
// One client is usually sufficient for the complete runtime of the API.
func New(nomadURL *url.URL) (ExecutorApi, error) {
client := &ApiClient{
nomadApiQuerier: &nomadApiClient{},
}
func NewExecutorApi(nomadURL *url.URL) (ExecutorApi, error) {
client := &ApiClient{apiQuerier: &nomadApiClient{}}
err := client.init(nomadURL)
return client, err
}

View File

@ -15,7 +15,7 @@ func TestLoadAvailableRunnersTestSuite(t *testing.T) {
type LoadAvailableRunnersTestSuite struct {
suite.Suite
jobId string
mock *nomadApiQuerierMock
mock *apiQuerierMock
nomadApiClient ApiClient
availableRunner *nomadApi.AllocationListStub
anotherAvailableRunner *nomadApi.AllocationListStub
@ -26,8 +26,8 @@ type LoadAvailableRunnersTestSuite struct {
func (suite *LoadAvailableRunnersTestSuite) SetupTest() {
suite.jobId = "1d-0f-v3ry-sp3c14l-j0b"
suite.mock = &nomadApiQuerierMock{}
suite.nomadApiClient = ApiClient{nomadApiQuerier: suite.mock}
suite.mock = &apiQuerierMock{}
suite.nomadApiClient = ApiClient{apiQuerier: suite.mock}
suite.availableRunner = &nomadApi.AllocationListStub{
ID: "s0m3-r4nd0m-1d",
@ -64,7 +64,7 @@ func (suite *LoadAvailableRunnersTestSuite) TestErrorOfUnderlyingApiCallIsPropag
suite.Error(err)
}
func (suite *LoadAvailableRunnersTestSuite) TestThrowsNoErrorWhenUnderlyingApiCallDoesnt() {
func (suite *LoadAvailableRunnersTestSuite) TestThrowsNoErrorWhenUnderlyingApiCallDoesNot() {
suite.mock.On("loadRunners", mock.AnythingOfType("string")).
Return([]*nomadApi.AllocationListStub{}, nil)