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

View File

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

View File

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

View File

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

View File

@ -5,9 +5,9 @@ import (
"net/url" "net/url"
) )
// ExecutorApi provides access to an container orchestration solution // ExecutorApi provides access to a container orchestration solution.
type ExecutorApi interface { type ExecutorApi interface {
nomadApiQuerier apiQuerier
// LoadAvailableRunners loads all allocations of the specified job which are running and not about to get stopped. // LoadAvailableRunners loads all allocations of the specified job which are running and not about to get stopped.
LoadAvailableRunners(jobId string) (runnerIds []string, err error) 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. // 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 { 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. // One client is usually sufficient for the complete runtime of the API.
func New(nomadURL *url.URL) (ExecutorApi, error) { func NewExecutorApi(nomadURL *url.URL) (ExecutorApi, error) {
client := &ApiClient{ client := &ApiClient{apiQuerier: &nomadApiClient{}}
nomadApiQuerier: &nomadApiClient{},
}
err := client.init(nomadURL) err := client.init(nomadURL)
return client, err return client, err
} }

View File

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