Allow using a local Docker image, e.g., for tests
This commit is contained in:

committed by
Sebastian Serth

parent
15b9117382
commit
7454e577e4
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
nomadApi "github.com/hashicorp/nomad/api"
|
||||
"github.com/openHPI/poseidon/internal/config"
|
||||
"github.com/openHPI/poseidon/pkg/dto"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -146,7 +147,11 @@ func FindAndValidateDefaultTask(taskGroup *nomadApi.TaskGroup) *nomadApi.Task {
|
||||
func SetForcePullFlag(job *nomadApi.Job, value bool) {
|
||||
taskGroup := FindAndValidateDefaultTaskGroup(job)
|
||||
task := FindAndValidateDefaultTask(taskGroup)
|
||||
task.Config["force_pull"] = value
|
||||
if config.Config.Nomad.DisableForcePull {
|
||||
task.Config["force_pull"] = false
|
||||
} else {
|
||||
task.Config["force_pull"] = value
|
||||
}
|
||||
}
|
||||
|
||||
// IsEnvironmentTemplateID checks if the passed job id belongs to a template job.
|
||||
|
@@ -2,6 +2,7 @@ package nomad
|
||||
|
||||
import (
|
||||
nomadApi "github.com/hashicorp/nomad/api"
|
||||
"github.com/openHPI/poseidon/internal/config"
|
||||
"github.com/openHPI/poseidon/pkg/dto"
|
||||
"github.com/openHPI/poseidon/tests/helpers"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -96,6 +97,27 @@ func TestFindOrCreateTask(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestSetForcePullFlag(t *testing.T) {
|
||||
_, job := helpers.CreateTemplateJob()
|
||||
taskGroup := FindAndValidateDefaultTaskGroup(job)
|
||||
task := FindAndValidateDefaultTask(taskGroup)
|
||||
|
||||
t.Run("Ignoring passed value if DisableForcePull", func(t *testing.T) {
|
||||
config.Config.Nomad.DisableForcePull = true
|
||||
SetForcePullFlag(job, true)
|
||||
assert.Equal(t, false, task.Config["force_pull"])
|
||||
})
|
||||
|
||||
t.Run("Using passed value if not DisableForcePull", func(t *testing.T) {
|
||||
config.Config.Nomad.DisableForcePull = false
|
||||
SetForcePullFlag(job, true)
|
||||
assert.Equal(t, true, task.Config["force_pull"])
|
||||
|
||||
SetForcePullFlag(job, false)
|
||||
assert.Equal(t, false, task.Config["force_pull"])
|
||||
})
|
||||
}
|
||||
|
||||
func TestIsEnvironmentTemplateID(t *testing.T) {
|
||||
assert.True(t, IsEnvironmentTemplateID("template-42"))
|
||||
assert.False(t, IsEnvironmentTemplateID("template-42-100"))
|
||||
|
Reference in New Issue
Block a user