change the packages
This commit is contained in:
parent
bea01efa5d
commit
11289526b5
|
@ -1,4 +1,4 @@
|
|||
package diff
|
||||
package flatmap
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package diff
|
||||
package flatmap
|
||||
|
||||
import (
|
||||
"reflect"
|
|
@ -1,10 +1,10 @@
|
|||
package diff
|
||||
package structs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
"github.com/hashicorp/nomad/helper/flatmap"
|
||||
"github.com/mitchellh/hashstructure"
|
||||
)
|
||||
|
||||
|
@ -152,7 +152,7 @@ type JobDiff struct {
|
|||
// TaskGroupsDiff contains the set of Task Groups that were changed.
|
||||
type TaskGroupsDiff struct {
|
||||
DiffEntry
|
||||
Added, Deleted []*structs.TaskGroup
|
||||
Added, Deleted []*TaskGroup
|
||||
Edited []*TaskGroupDiff
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ type TaskGroupDiff struct {
|
|||
// TasksDiff contains the set of Tasks that were changed.
|
||||
type TasksDiff struct {
|
||||
DiffEntry
|
||||
Added, Deleted []*structs.Task
|
||||
Added, Deleted []*Task
|
||||
Edited []*TaskDiff
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ type TaskDiff struct {
|
|||
// ServicesDiff contains the set of Services that were changed.
|
||||
type ServicesDiff struct {
|
||||
DiffEntry
|
||||
Added, Deleted []*structs.Service
|
||||
Added, Deleted []*Service
|
||||
Edited []*ServiceDiff
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ type ServiceDiff struct {
|
|||
// ServiceChecksDiff contains the set of Service Checks that were changed.
|
||||
type ServiceChecksDiff struct {
|
||||
DiffEntry
|
||||
Added, Deleted []*structs.ServiceCheck
|
||||
Added, Deleted []*ServiceCheck
|
||||
Edited []*ServiceCheckDiff
|
||||
}
|
||||
|
||||
|
@ -215,7 +215,7 @@ type ServiceCheckDiff struct {
|
|||
// TaskArtifactsDiff contains the set of Task Artifacts that were changed.
|
||||
type TaskArtifactsDiff struct {
|
||||
DiffEntry
|
||||
Added, Deleted []*structs.TaskArtifact
|
||||
Added, Deleted []*TaskArtifact
|
||||
Edited []*TaskArtifactDiff
|
||||
}
|
||||
|
||||
|
@ -247,7 +247,7 @@ type NetworkResourceDiff struct {
|
|||
// PortsDiff contains the difference between two sets of Ports.
|
||||
type PortsDiff struct {
|
||||
DiffEntry
|
||||
Added, Deleted []structs.Port
|
||||
Added, Deleted []Port
|
||||
Edited []*PrimitiveStructDiff
|
||||
}
|
||||
|
||||
|
@ -300,7 +300,7 @@ type StringValueDelta struct {
|
|||
|
||||
// NewJobDiff returns the diff between two jobs. If there is no difference, nil
|
||||
// is returned.
|
||||
func NewJobDiff(old, new *structs.Job) *JobDiff {
|
||||
func NewJobDiff(old, new *Job) *JobDiff {
|
||||
diff := &JobDiff{}
|
||||
diff.SetDiffType(old, new)
|
||||
if diff.Type == DiffTypeNone {
|
||||
|
@ -313,10 +313,10 @@ func NewJobDiff(old, new *structs.Job) *JobDiff {
|
|||
// Protect accessing nil fields, this occurs after diffing the primitives so
|
||||
// that we can properly detect Added/Deleted fields.
|
||||
if old == nil {
|
||||
old = &structs.Job{}
|
||||
old = &Job{}
|
||||
}
|
||||
if new == nil {
|
||||
new = &structs.Job{}
|
||||
new = &Job{}
|
||||
}
|
||||
|
||||
// Get the diff of the datacenters
|
||||
|
@ -355,7 +355,7 @@ func NewJobDiff(old, new *structs.Job) *JobDiff {
|
|||
|
||||
// NewTaskGroupDiff returns the diff between two task groups. If there is no
|
||||
// difference, nil is returned.
|
||||
func NewTaskGroupDiff(old, new *structs.TaskGroup) *TaskGroupDiff {
|
||||
func NewTaskGroupDiff(old, new *TaskGroup) *TaskGroupDiff {
|
||||
diff := &TaskGroupDiff{}
|
||||
diff.SetDiffType(old, new)
|
||||
if diff.Type == DiffTypeNone {
|
||||
|
@ -368,10 +368,10 @@ func NewTaskGroupDiff(old, new *structs.TaskGroup) *TaskGroupDiff {
|
|||
// Protect accessing nil fields, this occurs after diffing the primitives so
|
||||
// that we can properly detect Added/Deleted fields.
|
||||
if old == nil {
|
||||
old = &structs.TaskGroup{}
|
||||
old = &TaskGroup{}
|
||||
}
|
||||
if new == nil {
|
||||
new = &structs.TaskGroup{}
|
||||
new = &TaskGroup{}
|
||||
}
|
||||
|
||||
// Get the diff of the constraints.
|
||||
|
@ -402,7 +402,7 @@ func NewTaskGroupDiff(old, new *structs.TaskGroup) *TaskGroupDiff {
|
|||
|
||||
// NewTaskDiff returns the diff between two tasks. If there is no difference,
|
||||
// nil is returned.
|
||||
func NewTaskDiff(old, new *structs.Task) *TaskDiff {
|
||||
func NewTaskDiff(old, new *Task) *TaskDiff {
|
||||
diff := &TaskDiff{}
|
||||
diff.SetDiffType(old, new)
|
||||
if diff.Type == DiffTypeNone {
|
||||
|
@ -415,10 +415,10 @@ func NewTaskDiff(old, new *structs.Task) *TaskDiff {
|
|||
// Protect accessing nil fields, this occurs after diffing the primitives so
|
||||
// that we can properly detect Added/Deleted fields.
|
||||
if old == nil {
|
||||
old = &structs.Task{}
|
||||
old = &Task{}
|
||||
}
|
||||
if new == nil {
|
||||
new = &structs.Task{}
|
||||
new = &Task{}
|
||||
}
|
||||
|
||||
// Get the diff of the constraints.
|
||||
|
@ -444,7 +444,7 @@ func NewTaskDiff(old, new *structs.Task) *TaskDiff {
|
|||
diff.Resources = NewResourcesDiff(old.Resources, new.Resources)
|
||||
|
||||
// Get the task config diff
|
||||
diff.Config = NewStringMapDiff(Flatten(old.Config), Flatten(new.Config))
|
||||
diff.Config = NewStringMapDiff(flatmap.Flatten(old.Config), flatmap.Flatten(new.Config))
|
||||
|
||||
// If there are no changes return nil
|
||||
if len(diff.PrimitiveFields)+len(diff.Constraints) == 0 &&
|
||||
|
@ -462,7 +462,7 @@ func NewTaskDiff(old, new *structs.Task) *TaskDiff {
|
|||
|
||||
// NewServiceDiff returns the diff between two services. If there is no
|
||||
// difference, nil is returned.
|
||||
func NewServiceDiff(old, new *structs.Service) *ServiceDiff {
|
||||
func NewServiceDiff(old, new *Service) *ServiceDiff {
|
||||
diff := &ServiceDiff{}
|
||||
diff.SetDiffType(old, new)
|
||||
if diff.Type == DiffTypeNone {
|
||||
|
@ -475,10 +475,10 @@ func NewServiceDiff(old, new *structs.Service) *ServiceDiff {
|
|||
// Protect accessing nil fields, this occurs after diffing the primitives so
|
||||
// that we can properly detect Added/Deleted fields.
|
||||
if old == nil {
|
||||
old = &structs.Service{}
|
||||
old = &Service{}
|
||||
}
|
||||
if new == nil {
|
||||
new = &structs.Service{}
|
||||
new = &Service{}
|
||||
}
|
||||
|
||||
// Get the tags diff
|
||||
|
@ -499,7 +499,7 @@ func NewServiceDiff(old, new *structs.Service) *ServiceDiff {
|
|||
|
||||
// NewServiceCheckDiff returns the diff between two service checks. If there is
|
||||
// no difference, nil is returned.
|
||||
func NewServiceCheckDiff(old, new *structs.ServiceCheck) *ServiceCheckDiff {
|
||||
func NewServiceCheckDiff(old, new *ServiceCheck) *ServiceCheckDiff {
|
||||
diff := &ServiceCheckDiff{}
|
||||
diff.SetDiffType(old, new)
|
||||
if diff.Type == DiffTypeNone {
|
||||
|
@ -512,10 +512,10 @@ func NewServiceCheckDiff(old, new *structs.ServiceCheck) *ServiceCheckDiff {
|
|||
// Protect accessing nil fields, this occurs after diffing the primitives so
|
||||
// that we can properly detect Added/Deleted fields.
|
||||
if old == nil {
|
||||
old = &structs.ServiceCheck{}
|
||||
old = &ServiceCheck{}
|
||||
}
|
||||
if new == nil {
|
||||
new = &structs.ServiceCheck{}
|
||||
new = &ServiceCheck{}
|
||||
}
|
||||
|
||||
// Get the args diff
|
||||
|
@ -532,7 +532,7 @@ func NewServiceCheckDiff(old, new *structs.ServiceCheck) *ServiceCheckDiff {
|
|||
|
||||
// NewTaskArtifactDiff returns the diff between two task artifacts. If there is
|
||||
// no difference, nil is returned.
|
||||
func NewTaskArtifactDiff(old, new *structs.TaskArtifact) *TaskArtifactDiff {
|
||||
func NewTaskArtifactDiff(old, new *TaskArtifact) *TaskArtifactDiff {
|
||||
diff := &TaskArtifactDiff{}
|
||||
diff.SetDiffType(old, new)
|
||||
if diff.Type == DiffTypeNone {
|
||||
|
@ -545,10 +545,10 @@ func NewTaskArtifactDiff(old, new *structs.TaskArtifact) *TaskArtifactDiff {
|
|||
// Protect accessing nil fields, this occurs after diffing the primitives so
|
||||
// that we can properly detect Added/Deleted fields.
|
||||
if old == nil {
|
||||
old = &structs.TaskArtifact{}
|
||||
old = &TaskArtifact{}
|
||||
}
|
||||
if new == nil {
|
||||
new = &structs.TaskArtifact{}
|
||||
new = &TaskArtifact{}
|
||||
}
|
||||
|
||||
// Get the args diff
|
||||
|
@ -565,7 +565,7 @@ func NewTaskArtifactDiff(old, new *structs.TaskArtifact) *TaskArtifactDiff {
|
|||
|
||||
// NewResourcesDiff returns the diff between two resources. If there is no
|
||||
// difference, nil is returned.
|
||||
func NewResourcesDiff(old, new *structs.Resources) *ResourcesDiff {
|
||||
func NewResourcesDiff(old, new *Resources) *ResourcesDiff {
|
||||
diff := &ResourcesDiff{}
|
||||
diff.SetDiffType(old, new)
|
||||
if diff.Type == DiffTypeNone {
|
||||
|
@ -578,10 +578,10 @@ func NewResourcesDiff(old, new *structs.Resources) *ResourcesDiff {
|
|||
// Protect accessing nil fields, this occurs after diffing the primitives so
|
||||
// that we can properly detect Added/Deleted fields.
|
||||
if old == nil {
|
||||
old = &structs.Resources{}
|
||||
old = &Resources{}
|
||||
}
|
||||
if new == nil {
|
||||
new = &structs.Resources{}
|
||||
new = &Resources{}
|
||||
}
|
||||
|
||||
// Get the network resource diff
|
||||
|
@ -598,7 +598,7 @@ func NewResourcesDiff(old, new *structs.Resources) *ResourcesDiff {
|
|||
|
||||
// NewNetworkResourceDiff returns the diff between two network resources. If
|
||||
// there is no difference, nil is returned.
|
||||
func NewNetworkResourceDiff(old, new *structs.NetworkResource) *NetworkResourceDiff {
|
||||
func NewNetworkResourceDiff(old, new *NetworkResource) *NetworkResourceDiff {
|
||||
diff := &NetworkResourceDiff{}
|
||||
diff.SetDiffType(old, new)
|
||||
if diff.Type == DiffTypeNone {
|
||||
|
@ -611,10 +611,10 @@ func NewNetworkResourceDiff(old, new *structs.NetworkResource) *NetworkResourceD
|
|||
// Protect accessing nil fields, this occurs after diffing the primitives so
|
||||
// that we can properly detect Added/Deleted fields.
|
||||
if old == nil {
|
||||
old = &structs.NetworkResource{}
|
||||
old = &NetworkResource{}
|
||||
}
|
||||
if new == nil {
|
||||
new = &structs.NetworkResource{}
|
||||
new = &NetworkResource{}
|
||||
}
|
||||
|
||||
// Get the port diffs
|
||||
|
@ -780,11 +780,11 @@ func NewStringMapDiff(old, new map[string]string) *StringMapDiff {
|
|||
|
||||
// setDiffTaskGroups does a set difference of task groups using the task group
|
||||
// name as a key.
|
||||
func setDiffTaskGroups(old, new []*structs.TaskGroup) *TaskGroupsDiff {
|
||||
func setDiffTaskGroups(old, new []*TaskGroup) *TaskGroupsDiff {
|
||||
diff := &TaskGroupsDiff{}
|
||||
|
||||
oldMap := make(map[string]*structs.TaskGroup)
|
||||
newMap := make(map[string]*structs.TaskGroup)
|
||||
oldMap := make(map[string]*TaskGroup)
|
||||
newMap := make(map[string]*TaskGroup)
|
||||
for _, tg := range old {
|
||||
oldMap[tg.Name] = tg
|
||||
}
|
||||
|
@ -818,11 +818,11 @@ func setDiffTaskGroups(old, new []*structs.TaskGroup) *TaskGroupsDiff {
|
|||
}
|
||||
|
||||
// setDiffTasks does a set difference of tasks using the task name as a key.
|
||||
func setDiffTasks(old, new []*structs.Task) *TasksDiff {
|
||||
func setDiffTasks(old, new []*Task) *TasksDiff {
|
||||
diff := &TasksDiff{}
|
||||
|
||||
oldMap := make(map[string]*structs.Task)
|
||||
newMap := make(map[string]*structs.Task)
|
||||
oldMap := make(map[string]*Task)
|
||||
newMap := make(map[string]*Task)
|
||||
for _, task := range old {
|
||||
oldMap[task.Name] = task
|
||||
}
|
||||
|
@ -857,11 +857,11 @@ func setDiffTasks(old, new []*structs.Task) *TasksDiff {
|
|||
|
||||
// setDiffServices does a set difference of Services using the service name as a
|
||||
// key.
|
||||
func setDiffServices(old, new []*structs.Service) *ServicesDiff {
|
||||
func setDiffServices(old, new []*Service) *ServicesDiff {
|
||||
diff := &ServicesDiff{}
|
||||
|
||||
oldMap := make(map[string]*structs.Service)
|
||||
newMap := make(map[string]*structs.Service)
|
||||
oldMap := make(map[string]*Service)
|
||||
newMap := make(map[string]*Service)
|
||||
for _, s := range old {
|
||||
oldMap[s.Name] = s
|
||||
}
|
||||
|
@ -896,11 +896,11 @@ func setDiffServices(old, new []*structs.Service) *ServicesDiff {
|
|||
|
||||
// setDiffServiceChecks does a set difference of service checks using the check
|
||||
// name as a key.
|
||||
func setDiffServiceChecks(old, new []*structs.ServiceCheck) *ServiceChecksDiff {
|
||||
func setDiffServiceChecks(old, new []*ServiceCheck) *ServiceChecksDiff {
|
||||
diff := &ServiceChecksDiff{}
|
||||
|
||||
oldMap := make(map[string]*structs.ServiceCheck)
|
||||
newMap := make(map[string]*structs.ServiceCheck)
|
||||
oldMap := make(map[string]*ServiceCheck)
|
||||
newMap := make(map[string]*ServiceCheck)
|
||||
for _, s := range old {
|
||||
oldMap[s.Name] = s
|
||||
}
|
||||
|
@ -935,11 +935,11 @@ func setDiffServiceChecks(old, new []*structs.ServiceCheck) *ServiceChecksDiff {
|
|||
|
||||
// setDiffTaskArtifacts does a set difference of task artifacts using the geter
|
||||
// source as a key.
|
||||
func setDiffTaskArtifacts(old, new []*structs.TaskArtifact) *TaskArtifactsDiff {
|
||||
func setDiffTaskArtifacts(old, new []*TaskArtifact) *TaskArtifactsDiff {
|
||||
diff := &TaskArtifactsDiff{}
|
||||
|
||||
oldMap := make(map[string]*structs.TaskArtifact)
|
||||
newMap := make(map[string]*structs.TaskArtifact)
|
||||
oldMap := make(map[string]*TaskArtifact)
|
||||
newMap := make(map[string]*TaskArtifact)
|
||||
for _, ta := range old {
|
||||
oldMap[ta.GetterSource] = ta
|
||||
}
|
||||
|
@ -973,16 +973,16 @@ func setDiffTaskArtifacts(old, new []*structs.TaskArtifact) *TaskArtifactsDiff {
|
|||
}
|
||||
|
||||
// setDiffNetworkResources does a set difference of network resources.
|
||||
func setDiffNetworkResources(old, new []*structs.NetworkResource) *NetworkResourcesDiff {
|
||||
func setDiffNetworkResources(old, new []*NetworkResource) *NetworkResourcesDiff {
|
||||
diff := &NetworkResourcesDiff{}
|
||||
|
||||
added, del := setDifference(interfaceSlice(old), interfaceSlice(new))
|
||||
for _, a := range added {
|
||||
nDiff := NewNetworkResourceDiff(nil, a.(*structs.NetworkResource))
|
||||
nDiff := NewNetworkResourceDiff(nil, a.(*NetworkResource))
|
||||
diff.Added = append(diff.Added, nDiff)
|
||||
}
|
||||
for _, d := range del {
|
||||
nDiff := NewNetworkResourceDiff(d.(*structs.NetworkResource), nil)
|
||||
nDiff := NewNetworkResourceDiff(d.(*NetworkResource), nil)
|
||||
diff.Added = append(diff.Deleted, nDiff)
|
||||
}
|
||||
|
||||
|
@ -990,11 +990,11 @@ func setDiffNetworkResources(old, new []*structs.NetworkResource) *NetworkResour
|
|||
}
|
||||
|
||||
// setDiffPorts does a set difference of ports using the label as a key.
|
||||
func setDiffPorts(old, new []structs.Port) *PortsDiff {
|
||||
func setDiffPorts(old, new []Port) *PortsDiff {
|
||||
diff := &PortsDiff{}
|
||||
|
||||
oldMap := make(map[string]structs.Port)
|
||||
newMap := make(map[string]structs.Port)
|
||||
oldMap := make(map[string]Port)
|
||||
newMap := make(map[string]Port)
|
||||
for _, p := range old {
|
||||
oldMap[p.Label] = p
|
||||
}
|
|
@ -1,28 +1,24 @@
|
|||
package diff
|
||||
package structs
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/hashicorp/nomad/nomad/mock"
|
||||
"github.com/hashicorp/nomad/nomad/structs"
|
||||
)
|
||||
|
||||
func TestNewJobDiff_Same(t *testing.T) {
|
||||
job1 := mock.Job()
|
||||
job2 := mock.Job()
|
||||
job1 := TestJob()
|
||||
job2 := TestJob()
|
||||
job2.ID = job1.ID
|
||||
|
||||
diff := NewJobDiff(job1, job2)
|
||||
if diff != nil {
|
||||
t.Fatalf("expected nil job diff; got %s", spew.Sdump(diff))
|
||||
t.Fatalf("expected nil job diff; got %#v", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewJobDiff_NilCases(t *testing.T) {
|
||||
j := mock.Job()
|
||||
j := TestJob()
|
||||
|
||||
// Old job nil
|
||||
diff := NewJobDiff(nil, j)
|
||||
|
@ -30,7 +26,6 @@ func TestNewJobDiff_NilCases(t *testing.T) {
|
|||
t.Fatalf("expected non-nil job diff")
|
||||
}
|
||||
if diff.Type != DiffTypeAdded {
|
||||
//t.Fatalf("got diff type %v; want %v; %s", diff.Type, DiffTypeAdded, spew.Sdump(diff))
|
||||
t.Fatalf("got diff type %v; want %v", diff.Type, DiffTypeAdded)
|
||||
}
|
||||
|
||||
|
@ -45,13 +40,13 @@ func TestNewJobDiff_NilCases(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNewJobDiff_Constraints(t *testing.T) {
|
||||
c1 := &structs.Constraint{LTarget: "foo"}
|
||||
c2 := &structs.Constraint{LTarget: "bar"}
|
||||
c3 := &structs.Constraint{LTarget: "baz"}
|
||||
c1 := &Constraint{LTarget: "foo"}
|
||||
c2 := &Constraint{LTarget: "bar"}
|
||||
c3 := &Constraint{LTarget: "baz"}
|
||||
|
||||
// Test the added case.
|
||||
j1 := &structs.Job{Constraints: []*structs.Constraint{c1, c2}}
|
||||
j2 := &structs.Job{Constraints: []*structs.Constraint{c1, c2, c3}}
|
||||
j1 := &Job{Constraints: []*Constraint{c1, c2}}
|
||||
j2 := &Job{Constraints: []*Constraint{c1, c2, c3}}
|
||||
|
||||
diff := NewJobDiff(j1, j2)
|
||||
if diff == nil {
|
||||
|
@ -75,8 +70,8 @@ func TestNewJobDiff_Constraints(t *testing.T) {
|
|||
}
|
||||
|
||||
// Test the deleted case.
|
||||
j1 = &structs.Job{Constraints: []*structs.Constraint{c1, c2}}
|
||||
j2 = &structs.Job{Constraints: []*structs.Constraint{c1}}
|
||||
j1 = &Job{Constraints: []*Constraint{c1, c2}}
|
||||
j2 = &Job{Constraints: []*Constraint{c1}}
|
||||
|
||||
diff = NewJobDiff(j1, j2)
|
||||
if diff == nil {
|
||||
|
@ -101,8 +96,8 @@ func TestNewJobDiff_Constraints(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNewJobDiff_Datacenters(t *testing.T) {
|
||||
j1 := &structs.Job{Datacenters: []string{"a", "b"}}
|
||||
j2 := &structs.Job{Datacenters: []string{"b", "c"}}
|
||||
j1 := &Job{Datacenters: []string{"a", "b"}}
|
||||
j2 := &Job{Datacenters: []string{"b", "c"}}
|
||||
|
||||
diff := NewJobDiff(j1, j2)
|
||||
if diff == nil {
|
||||
|
@ -126,13 +121,13 @@ func TestNewJobDiff_Datacenters(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNewJobDiff_TaskGroups(t *testing.T) {
|
||||
tg1 := &structs.TaskGroup{Name: "foo"}
|
||||
tg2 := &structs.TaskGroup{Name: "bar"}
|
||||
tg2_2 := &structs.TaskGroup{Name: "bar", Count: 2}
|
||||
tg3 := &structs.TaskGroup{Name: "baz"}
|
||||
tg1 := &TaskGroup{Name: "foo"}
|
||||
tg2 := &TaskGroup{Name: "bar"}
|
||||
tg2_2 := &TaskGroup{Name: "bar", Count: 2}
|
||||
tg3 := &TaskGroup{Name: "baz"}
|
||||
|
||||
j1 := &structs.Job{TaskGroups: []*structs.TaskGroup{tg1, tg2}}
|
||||
j2 := &structs.Job{TaskGroups: []*structs.TaskGroup{tg2_2, tg3}}
|
||||
j1 := &Job{TaskGroups: []*TaskGroup{tg1, tg2}}
|
||||
j2 := &Job{TaskGroups: []*TaskGroup{tg2_2, tg3}}
|
||||
|
||||
diff := NewJobDiff(j1, j2)
|
||||
if diff == nil {
|
||||
|
@ -148,8 +143,8 @@ func TestNewJobDiff_TaskGroups(t *testing.T) {
|
|||
t.Fatalf("expected task group diff")
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(tgd.Added, []*structs.TaskGroup{tg3}) ||
|
||||
!reflect.DeepEqual(tgd.Deleted, []*structs.TaskGroup{tg1}) {
|
||||
if !reflect.DeepEqual(tgd.Added, []*TaskGroup{tg3}) ||
|
||||
!reflect.DeepEqual(tgd.Deleted, []*TaskGroup{tg1}) {
|
||||
t.Fatalf("bad: %#v", tgd)
|
||||
}
|
||||
|
||||
|
@ -174,7 +169,7 @@ func TestNewTaskDiff_Config(t *testing.T) {
|
|||
c3 := map[string]interface{}{
|
||||
"command": "/bin/date",
|
||||
"args": []string{"1", "2"},
|
||||
"nested": &structs.Port{
|
||||
"nested": &Port{
|
||||
Label: "http",
|
||||
Value: 80,
|
||||
},
|
||||
|
@ -186,7 +181,7 @@ func TestNewTaskDiff_Config(t *testing.T) {
|
|||
}
|
||||
|
||||
// No old case
|
||||
t1 := &structs.Task{Config: c1}
|
||||
t1 := &Task{Config: c1}
|
||||
diff := NewTaskDiff(nil, t1)
|
||||
if diff == nil {
|
||||
t.Fatalf("expected non-nil diff")
|
||||
|
@ -221,7 +216,7 @@ func TestNewTaskDiff_Config(t *testing.T) {
|
|||
}
|
||||
|
||||
// Deleted case
|
||||
t2 := &structs.Task{Config: c2}
|
||||
t2 := &Task{Config: c2}
|
||||
diff = NewTaskDiff(t1, t2)
|
||||
if diff == nil {
|
||||
t.Fatalf("expected non-nil diff")
|
||||
|
@ -244,7 +239,7 @@ func TestNewTaskDiff_Config(t *testing.T) {
|
|||
}
|
||||
|
||||
// Added case
|
||||
t3 := &structs.Task{Config: c3}
|
||||
t3 := &Task{Config: c3}
|
||||
diff = NewTaskDiff(t1, t3)
|
||||
if diff == nil {
|
||||
t.Fatalf("expected non-nil diff")
|
||||
|
@ -270,7 +265,7 @@ func TestNewTaskDiff_Config(t *testing.T) {
|
|||
}
|
||||
|
||||
// Edited case
|
||||
t4 := &structs.Task{Config: c4}
|
||||
t4 := &Task{Config: c4}
|
||||
diff = NewTaskDiff(t1, t4)
|
||||
if diff == nil {
|
||||
t.Fatalf("expected non-nil diff")
|
||||
|
@ -297,9 +292,9 @@ func TestNewTaskDiff_Config(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNewPrimitiveStructDiff(t *testing.T) {
|
||||
p1 := structs.Port{Label: "1"}
|
||||
p2 := structs.Port{Label: "2"}
|
||||
p3 := structs.Port{}
|
||||
p1 := Port{Label: "1"}
|
||||
p2 := Port{Label: "2"}
|
||||
p3 := Port{}
|
||||
|
||||
pdiff := NewPrimitiveStructDiff(nil, nil, portFields)
|
||||
if pdiff != nil {
|
||||
|
@ -373,15 +368,15 @@ func TestNewPrimitiveStructDiff(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSetDiffPrimitiveStructs(t *testing.T) {
|
||||
p1 := structs.Port{Label: "1"}
|
||||
p2 := structs.Port{Label: "2"}
|
||||
p3 := structs.Port{Label: "3"}
|
||||
p4 := structs.Port{Label: "4"}
|
||||
p5 := structs.Port{Label: "5"}
|
||||
p6 := structs.Port{Label: "6"}
|
||||
p1 := Port{Label: "1"}
|
||||
p2 := Port{Label: "2"}
|
||||
p3 := Port{Label: "3"}
|
||||
p4 := Port{Label: "4"}
|
||||
p5 := Port{Label: "5"}
|
||||
p6 := Port{Label: "6"}
|
||||
|
||||
old := []structs.Port{p1, p2, p3, p4}
|
||||
new := []structs.Port{p3, p4, p5, p6}
|
||||
old := []Port{p1, p2, p3, p4}
|
||||
new := []Port{p3, p4, p5, p6}
|
||||
|
||||
diffs := setDiffPrimitiveStructs(interfaceSlice(old), interfaceSlice(new), portFields)
|
||||
if len(diffs) != 4 {
|
||||
|
@ -634,9 +629,9 @@ func TestKeyedSetDifference(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestInterfaceSlice(t *testing.T) {
|
||||
j1 := mock.Job()
|
||||
j2 := mock.Job()
|
||||
jobs := []*structs.Job{j1, j2}
|
||||
j1 := TestJob()
|
||||
j2 := TestJob()
|
||||
jobs := []*Job{j1, j2}
|
||||
|
||||
slice := interfaceSlice(jobs)
|
||||
if len(slice) != 2 {
|
||||
|
@ -644,7 +639,7 @@ func TestInterfaceSlice(t *testing.T) {
|
|||
}
|
||||
|
||||
f := slice[0]
|
||||
actJob1, ok := f.(*structs.Job)
|
||||
actJob1, ok := f.(*Job)
|
||||
if !ok {
|
||||
t.Fatalf("unexpected type: %v", actJob1)
|
||||
}
|
||||
|
@ -655,7 +650,7 @@ func TestInterfaceSlice(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetField(t *testing.T) {
|
||||
j := mock.Job()
|
||||
j := TestJob()
|
||||
exp := "foo"
|
||||
j.Type = "foo"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package diff
|
||||
package structs
|
||||
|
||||
// JobVisitor is the set of types a visitor must implement to traverse a JobDiff
|
||||
// structure.
|
|
@ -93,82 +93,8 @@ func TestJob_Validate(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func testJob() *Job {
|
||||
return &Job{
|
||||
Region: "global",
|
||||
ID: GenerateUUID(),
|
||||
Name: "my-job",
|
||||
Type: JobTypeService,
|
||||
Priority: 50,
|
||||
AllAtOnce: false,
|
||||
Datacenters: []string{"dc1"},
|
||||
Constraints: []*Constraint{
|
||||
&Constraint{
|
||||
LTarget: "$attr.kernel.name",
|
||||
RTarget: "linux",
|
||||
Operand: "=",
|
||||
},
|
||||
},
|
||||
Periodic: &PeriodicConfig{
|
||||
Enabled: false,
|
||||
},
|
||||
TaskGroups: []*TaskGroup{
|
||||
&TaskGroup{
|
||||
Name: "web",
|
||||
Count: 10,
|
||||
RestartPolicy: &RestartPolicy{
|
||||
Attempts: 3,
|
||||
Interval: 10 * time.Minute,
|
||||
Delay: 1 * time.Minute,
|
||||
},
|
||||
Tasks: []*Task{
|
||||
&Task{
|
||||
Name: "web",
|
||||
Driver: "exec",
|
||||
Config: map[string]interface{}{
|
||||
"command": "/bin/date",
|
||||
},
|
||||
Env: map[string]string{
|
||||
"FOO": "bar",
|
||||
},
|
||||
Artifacts: []*TaskArtifact{
|
||||
{
|
||||
GetterSource: "http://foo.com",
|
||||
},
|
||||
},
|
||||
Services: []*Service{
|
||||
{
|
||||
Name: "${TASK}-frontend",
|
||||
PortLabel: "http",
|
||||
},
|
||||
},
|
||||
Resources: &Resources{
|
||||
CPU: 500,
|
||||
MemoryMB: 256,
|
||||
Networks: []*NetworkResource{
|
||||
&NetworkResource{
|
||||
MBits: 50,
|
||||
DynamicPorts: []Port{{Label: "http"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Meta: map[string]string{
|
||||
"elb_check_type": "http",
|
||||
"elb_check_interval": "30s",
|
||||
"elb_check_min": "3",
|
||||
},
|
||||
},
|
||||
},
|
||||
Meta: map[string]string{
|
||||
"owner": "armon",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestJob_Copy(t *testing.T) {
|
||||
j := testJob()
|
||||
j := TestJob()
|
||||
c := j.Copy()
|
||||
if !reflect.DeepEqual(j, c) {
|
||||
t.Fatalf("Copy() returned an unequal Job; got %#v; want %#v", c, j)
|
||||
|
@ -528,7 +454,7 @@ func TestEncodeDecode(t *testing.T) {
|
|||
}
|
||||
|
||||
func BenchmarkEncodeDecode(b *testing.B) {
|
||||
job := testJob()
|
||||
job := TestJob()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
buf, err := Encode(1, job)
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
package structs
|
||||
|
||||
import "time"
|
||||
|
||||
func TestJob() *Job {
|
||||
return &Job{
|
||||
Region: "global",
|
||||
ID: GenerateUUID(),
|
||||
Name: "my-job",
|
||||
Type: JobTypeService,
|
||||
Priority: 50,
|
||||
AllAtOnce: false,
|
||||
Datacenters: []string{"dc1"},
|
||||
Constraints: []*Constraint{
|
||||
&Constraint{
|
||||
LTarget: "$attr.kernel.name",
|
||||
RTarget: "linux",
|
||||
Operand: "=",
|
||||
},
|
||||
},
|
||||
Periodic: &PeriodicConfig{
|
||||
Enabled: false,
|
||||
},
|
||||
TaskGroups: []*TaskGroup{
|
||||
&TaskGroup{
|
||||
Name: "web",
|
||||
Count: 10,
|
||||
RestartPolicy: &RestartPolicy{
|
||||
Attempts: 3,
|
||||
Interval: 10 * time.Minute,
|
||||
Delay: 1 * time.Minute,
|
||||
},
|
||||
Tasks: []*Task{
|
||||
&Task{
|
||||
Name: "web",
|
||||
Driver: "exec",
|
||||
Config: map[string]interface{}{
|
||||
"command": "/bin/date",
|
||||
},
|
||||
Env: map[string]string{
|
||||
"FOO": "bar",
|
||||
},
|
||||
Artifacts: []*TaskArtifact{
|
||||
{
|
||||
GetterSource: "http://foo.com",
|
||||
},
|
||||
},
|
||||
Services: []*Service{
|
||||
{
|
||||
Name: "${TASK}-frontend",
|
||||
PortLabel: "http",
|
||||
},
|
||||
},
|
||||
Resources: &Resources{
|
||||
CPU: 500,
|
||||
MemoryMB: 256,
|
||||
Networks: []*NetworkResource{
|
||||
&NetworkResource{
|
||||
MBits: 50,
|
||||
DynamicPorts: []Port{{Label: "http"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Meta: map[string]string{
|
||||
"elb_check_type": "http",
|
||||
"elb_check_interval": "30s",
|
||||
"elb_check_min": "3",
|
||||
},
|
||||
},
|
||||
},
|
||||
Meta: map[string]string{
|
||||
"owner": "armon",
|
||||
},
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue