Add tests for api client creation
This commit is contained in:
@ -238,7 +238,7 @@ func TestConfigureTaskWhenTaskExists(t *testing.T) {
|
||||
|
||||
func TestCreateJobSetsAllGivenArguments(t *testing.T) {
|
||||
testJob, base := createTestJob()
|
||||
apiClient := ApiClient{&nomadApi.Client{}, *base}
|
||||
apiClient := ApiClient{&nomadApiClient{}, &nomadApi.Client{}, *base}
|
||||
job := apiClient.createJob(
|
||||
*testJob.ID,
|
||||
uint(*testJob.TaskGroups[0].Count),
|
||||
|
@ -44,9 +44,9 @@ func (apiClient *ApiClient) init(nomadURL *url.URL) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadRunners loads the allocations of the specified job.
|
||||
func (apiClient *ApiClient) LoadRunners(jobId string) (runnerIds []string, err error) {
|
||||
list, _, err := apiClient.client.Jobs().Allocations(jobId, true, nil)
|
||||
// LoadAvailableRunners loads the allocations of the specified job.
|
||||
func (apiClient *ApiClient) LoadAvailableRunners(jobId string) (runnerIds []string, err error) {
|
||||
list, err := apiClient.loadRunners(jobId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -3,8 +3,11 @@ package nomad
|
||||
import (
|
||||
"errors"
|
||||
nomadApi "github.com/hashicorp/nomad/api"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"net/url"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@ -112,3 +115,34 @@ func (suite *LoadAvailableRunnersTestSuite) TestReturnsAllAvailableRunners() {
|
||||
suite.Contains(returnedIds, suite.availableRunner.ID)
|
||||
suite.Contains(returnedIds, suite.anotherAvailableRunner.ID)
|
||||
}
|
||||
|
||||
var TestURL = url.URL{
|
||||
Scheme: "http",
|
||||
Host: "127.0.0.1:4646",
|
||||
}
|
||||
|
||||
func TestApiClient_init(t *testing.T) {
|
||||
client := &ApiClient{}
|
||||
defaultJob := parseJob(defaultJobHCL)
|
||||
err := client.init(&TestURL)
|
||||
require.Nil(t, err)
|
||||
assert.Equal(t, *defaultJob, client.defaultJob)
|
||||
}
|
||||
|
||||
func TestApiClientCanNotBeInitializedWithInvalidUrl(t *testing.T) {
|
||||
client := &ApiClient{}
|
||||
err := client.init(&url.URL{
|
||||
Scheme: "http",
|
||||
Host: "http://127.0.0.1:4646",
|
||||
})
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
||||
func TestNewExecutorApiCanBeCreatedWithoutError(t *testing.T) {
|
||||
expectedClient := &ApiClient{}
|
||||
err := expectedClient.init(&TestURL)
|
||||
require.Nil(t, err)
|
||||
|
||||
_, err = NewExecutorApi(&TestURL)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user