From fde334a610a9d84d456731353be3b124e15a38ce Mon Sep 17 00:00:00 2001 From: Jan-Eric Hellenberg Date: Tue, 11 May 2021 10:38:01 +0200 Subject: [PATCH] Perform a few renamings --- .gitlab-ci.yml | 4 ++-- main.go | 2 +- nomad/api_querier.go | 4 ++-- ...omadApiQuerierMock.go => api_querier_mock.go} | 16 ++++++++-------- .../{ExecutorApiMock.go => executor_api_mock.go} | 0 nomad/nomad.go | 14 ++++++-------- nomad/nomad_test.go | 8 ++++---- 7 files changed, 23 insertions(+), 25 deletions(-) rename nomad/{nomadApiQuerierMock.go => api_querier_mock.go} (78%) rename nomad/{ExecutorApiMock.go => executor_api_mock.go} (100%) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 92a794d..78af8e7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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: diff --git a/main.go b/main.go index 87c7340..022f7f3 100644 --- a/main.go +++ b/main.go @@ -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") } diff --git a/nomad/api_querier.go b/nomad/api_querier.go index 2402445..c545c96 100644 --- a/nomad/api_querier.go +++ b/nomad/api_querier.go @@ -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) diff --git a/nomad/nomadApiQuerierMock.go b/nomad/api_querier_mock.go similarity index 78% rename from nomad/nomadApiQuerierMock.go rename to nomad/api_querier_mock.go index 59f7393..2e7e4e3 100644 --- a/nomad/nomadApiQuerierMock.go +++ b/nomad/api_querier_mock.go @@ -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 diff --git a/nomad/ExecutorApiMock.go b/nomad/executor_api_mock.go similarity index 100% rename from nomad/ExecutorApiMock.go rename to nomad/executor_api_mock.go diff --git a/nomad/nomad.go b/nomad/nomad.go index 075e005..ee09d5f 100644 --- a/nomad/nomad.go +++ b/nomad/nomad.go @@ -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 } diff --git a/nomad/nomad_test.go b/nomad/nomad_test.go index fc86653..714015f 100644 --- a/nomad/nomad_test.go +++ b/nomad/nomad_test.go @@ -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)