Add tests for api client creation

This commit is contained in:
sirkrypt0
2021-05-10 11:58:28 +02:00
committed by Konrad Hanff
parent 9879b152e5
commit a2a9ed367a
3 changed files with 38 additions and 4 deletions

View File

@@ -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)
}