[marathon] Use test builder.
This change introduces the builder pattern to the Marathon unit tests in order to simplify and reduce the amount of testing boilerplate. Additional changes: - Add missing unit tests. - Make all tests look consistent. - Use dedicated type for task states for increased type safety. - Remove obsoleted getApplication function.
This commit is contained in:
parent
69c628b626
commit
8cb44598c0
4 changed files with 800 additions and 858 deletions
|
@ -26,7 +26,14 @@ import (
|
|||
|
||||
const (
|
||||
traceMaxScanTokenSize = 1024 * 1024
|
||||
taskStateRunning = "TASK_RUNNING"
|
||||
)
|
||||
|
||||
// TaskState denotes the Mesos state a task can have.
|
||||
type TaskState string
|
||||
|
||||
const (
|
||||
taskStateRunning TaskState = "TASK_RUNNING"
|
||||
taskStateStaging TaskState = "TASK_STAGING"
|
||||
)
|
||||
|
||||
var _ provider.Provider = (*Provider)(nil)
|
||||
|
@ -222,7 +229,7 @@ func (p *Provider) applicationFilter(app marathon.Application) bool {
|
|||
}
|
||||
|
||||
func (p *Provider) taskFilter(task marathon.Task, application marathon.Application) bool {
|
||||
if task.State != taskStateRunning {
|
||||
if task.State != string(taskStateRunning) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -254,15 +261,6 @@ func (p *Provider) taskFilter(task marathon.Task, application marathon.Applicati
|
|||
return true
|
||||
}
|
||||
|
||||
func getApplication(task marathon.Task, apps []marathon.Application) (marathon.Application, error) {
|
||||
for _, application := range apps {
|
||||
if application.ID == task.AppID {
|
||||
return application, nil
|
||||
}
|
||||
}
|
||||
return marathon.Application{}, errors.New("Application not found: " + task.AppID)
|
||||
}
|
||||
|
||||
func isApplicationEnabled(application marathon.Application, exposedByDefault bool) bool {
|
||||
return exposedByDefault && (*application.Labels)[types.LabelEnable] != "false" || (*application.Labels)[types.LabelEnable] == "true"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue