Commit 86bc2fbf authored by Michael Schurter's avatar Michael Schurter
Browse files

Fix diff test + bonus upgrade to subtests

parent 64057d48
Showing with 70 additions and 48 deletions
+70 -48
...@@ -1912,20 +1912,22 @@ func TestTaskGroupDiff(t *testing.T) { ...@@ -1912,20 +1912,22 @@ func TestTaskGroupDiff(t *testing.T) {
func TestTaskDiff(t *testing.T) { func TestTaskDiff(t *testing.T) {
cases := []struct { cases := []struct {
Name string
Old, New *Task Old, New *Task
Expected *TaskDiff Expected *TaskDiff
Error bool Error bool
Contextual bool Contextual bool
}{ }{
{ {
Old: nil, Name: "Empty",
New: nil, Old: nil,
New: nil,
Expected: &TaskDiff{ Expected: &TaskDiff{
Type: DiffTypeNone, Type: DiffTypeNone,
}, },
}, },
{ {
// Primitive only that has different names Name: "Primitive only that has different names",
Old: &Task{ Old: &Task{
Name: "foo", Name: "foo",
Meta: map[string]string{ Meta: map[string]string{
...@@ -1941,7 +1943,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -1941,7 +1943,7 @@ func TestTaskDiff(t *testing.T) {
Error: true, Error: true,
}, },
{ {
// Primitive only that is the same Name: "Primitive only that is the same",
Old: &Task{ Old: &Task{
Name: "foo", Name: "foo",
Driver: "exec", Driver: "exec",
...@@ -1974,7 +1976,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -1974,7 +1976,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Primitive only that has diffs Name: "Primitive only that has diffs",
Old: &Task{ Old: &Task{
Name: "foo", Name: "foo",
Driver: "exec", Driver: "exec",
...@@ -2045,7 +2047,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2045,7 +2047,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Map diff Name: "Map diff",
Old: &Task{ Old: &Task{
Meta: map[string]string{ Meta: map[string]string{
"foo": "foo", "foo": "foo",
...@@ -2097,7 +2099,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2097,7 +2099,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Constraints edited Name: "Constraints edited",
Old: &Task{ Old: &Task{
Constraints: []*Constraint{ Constraints: []*Constraint{
{ {
...@@ -2185,8 +2187,8 @@ func TestTaskDiff(t *testing.T) { ...@@ -2185,8 +2187,8 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// LogConfig added Name: "LogConfig added",
Old: &Task{}, Old: &Task{},
New: &Task{ New: &Task{
LogConfig: &LogConfig{ LogConfig: &LogConfig{
MaxFiles: 1, MaxFiles: 1,
...@@ -2218,7 +2220,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2218,7 +2220,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// LogConfig deleted Name: "LogConfig deleted",
Old: &Task{ Old: &Task{
LogConfig: &LogConfig{ LogConfig: &LogConfig{
MaxFiles: 1, MaxFiles: 1,
...@@ -2251,7 +2253,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2251,7 +2253,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// LogConfig edited Name: "LogConfig edited",
Old: &Task{ Old: &Task{
LogConfig: &LogConfig{ LogConfig: &LogConfig{
MaxFiles: 1, MaxFiles: 1,
...@@ -2289,7 +2291,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2289,7 +2291,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// LogConfig edited with context Name: "LogConfig edited with context",
Contextual: true, Contextual: true,
Old: &Task{ Old: &Task{
LogConfig: &LogConfig{ LogConfig: &LogConfig{
...@@ -2328,7 +2330,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2328,7 +2330,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Artifacts edited Name: "Artifacts edited",
Old: &Task{ Old: &Task{
Artifacts: []*TaskArtifact{ Artifacts: []*TaskArtifact{
{ {
...@@ -2420,7 +2422,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2420,7 +2422,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Resources edited (no networks) Name: "Resources edited (no networks)",
Old: &Task{ Old: &Task{
Resources: &Resources{ Resources: &Resources{
CPU: 100, CPU: 100,
...@@ -2474,7 +2476,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2474,7 +2476,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Resources edited (no networks) with context Name: "Resources edited (no networks) with context",
Contextual: true, Contextual: true,
Old: &Task{ Old: &Task{
Resources: &Resources{ Resources: &Resources{
...@@ -2529,7 +2531,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2529,7 +2531,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Network Resources edited Name: "Network Resources edited",
Old: &Task{ Old: &Task{
Resources: &Resources{ Resources: &Resources{
Networks: []*NetworkResource{ Networks: []*NetworkResource{
...@@ -2677,7 +2679,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2677,7 +2679,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Config same Name: "Config same",
Old: &Task{ Old: &Task{
Config: map[string]interface{}{ Config: map[string]interface{}{
"foo": 1, "foo": 1,
...@@ -2711,7 +2713,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2711,7 +2713,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Config edited Name: "Config edited",
Old: &Task{ Old: &Task{
Config: map[string]interface{}{ Config: map[string]interface{}{
"foo": 1, "foo": 1,
...@@ -2795,7 +2797,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2795,7 +2797,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Config edited with context Name: "Config edited with context",
Contextual: true, Contextual: true,
Old: &Task{ Old: &Task{
Config: map[string]interface{}{ Config: map[string]interface{}{
...@@ -2892,7 +2894,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2892,7 +2894,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Services edited (no checks) Name: "Services edited (no checks)",
Old: &Task{ Old: &Task{
Services: []*Service{ Services: []*Service{
{ {
...@@ -2980,7 +2982,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -2980,7 +2982,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Services edited (no checks) with context Name: "Services edited (no checks) with context",
Contextual: true, Contextual: true,
Old: &Task{ Old: &Task{
Services: []*Service{ Services: []*Service{
...@@ -3023,7 +3025,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -3023,7 +3025,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Service Checks edited Name: "Service Checks edited",
Old: &Task{ Old: &Task{
Services: []*Service{ Services: []*Service{
{ {
...@@ -3155,6 +3157,12 @@ func TestTaskDiff(t *testing.T) { ...@@ -3155,6 +3157,12 @@ func TestTaskDiff(t *testing.T) {
Old: "", Old: "",
New: "http", New: "http",
}, },
{
Type: DiffTypeAdded,
Name: "TLSSkipVerify",
Old: "",
New: "false",
},
{ {
Type: DiffTypeAdded, Type: DiffTypeAdded,
Name: "Timeout", Name: "Timeout",
...@@ -3203,6 +3211,12 @@ func TestTaskDiff(t *testing.T) { ...@@ -3203,6 +3211,12 @@ func TestTaskDiff(t *testing.T) {
Old: "http", Old: "http",
New: "", New: "",
}, },
{
Type: DiffTypeDeleted,
Name: "TLSSkipVerify",
Old: "false",
New: "",
},
{ {
Type: DiffTypeDeleted, Type: DiffTypeDeleted,
Name: "Timeout", Name: "Timeout",
...@@ -3223,7 +3237,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -3223,7 +3237,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Service Checks edited with context Name: "Service Checks edited with context",
Contextual: true, Contextual: true,
Old: &Task{ Old: &Task{
Services: []*Service{ Services: []*Service{
...@@ -3332,6 +3346,12 @@ func TestTaskDiff(t *testing.T) { ...@@ -3332,6 +3346,12 @@ func TestTaskDiff(t *testing.T) {
Old: "http", Old: "http",
New: "http", New: "http",
}, },
{
Type: DiffTypeNone,
Name: "TLSSkipVerify",
Old: "false",
New: "false",
},
{ {
Type: DiffTypeNone, Type: DiffTypeNone,
Name: "Timeout", Name: "Timeout",
...@@ -3352,8 +3372,8 @@ func TestTaskDiff(t *testing.T) { ...@@ -3352,8 +3372,8 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Vault added Name: "Vault added",
Old: &Task{}, Old: &Task{},
New: &Task{ New: &Task{
Vault: &Vault{ Vault: &Vault{
Policies: []string{"foo", "bar"}, Policies: []string{"foo", "bar"},
...@@ -3413,7 +3433,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -3413,7 +3433,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Vault deleted Name: "Vault deleted",
Old: &Task{ Old: &Task{
Vault: &Vault{ Vault: &Vault{
Policies: []string{"foo", "bar"}, Policies: []string{"foo", "bar"},
...@@ -3474,7 +3494,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -3474,7 +3494,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Vault edited Name: "Vault edited",
Old: &Task{ Old: &Task{
Vault: &Vault{ Vault: &Vault{
Policies: []string{"foo", "bar"}, Policies: []string{"foo", "bar"},
...@@ -3542,7 +3562,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -3542,7 +3562,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Vault edited with context Name: "Vault edited with context",
Contextual: true, Contextual: true,
Old: &Task{ Old: &Task{
Vault: &Vault{ Vault: &Vault{
...@@ -3617,7 +3637,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -3617,7 +3637,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Template edited Name: "Template edited",
Old: &Task{ Old: &Task{
Templates: []*Template{ Templates: []*Template{
{ {
...@@ -3765,8 +3785,8 @@ func TestTaskDiff(t *testing.T) { ...@@ -3765,8 +3785,8 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// DispatchPayload added Name: "DispatchPayload added",
Old: &Task{}, Old: &Task{},
New: &Task{ New: &Task{
DispatchPayload: &DispatchPayloadConfig{ DispatchPayload: &DispatchPayloadConfig{
File: "foo", File: "foo",
...@@ -3791,7 +3811,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -3791,7 +3811,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// DispatchPayload deleted Name: "DispatchPayload deleted",
Old: &Task{ Old: &Task{
DispatchPayload: &DispatchPayloadConfig{ DispatchPayload: &DispatchPayloadConfig{
File: "foo", File: "foo",
...@@ -3817,7 +3837,7 @@ func TestTaskDiff(t *testing.T) { ...@@ -3817,7 +3837,7 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// Dispatch payload edited Name: "Dispatch payload edited",
Old: &Task{ Old: &Task{
DispatchPayload: &DispatchPayloadConfig{ DispatchPayload: &DispatchPayloadConfig{
File: "foo", File: "foo",
...@@ -3847,8 +3867,8 @@ func TestTaskDiff(t *testing.T) { ...@@ -3847,8 +3867,8 @@ func TestTaskDiff(t *testing.T) {
}, },
}, },
{ {
// DispatchPayload edited with context. Place holder for if more // Place holder for if more fields are added
// fields are added Name: "DispatchPayload edited with context",
Contextual: true, Contextual: true,
Old: &Task{ Old: &Task{
DispatchPayload: &DispatchPayloadConfig{ DispatchPayload: &DispatchPayloadConfig{
...@@ -3881,20 +3901,22 @@ func TestTaskDiff(t *testing.T) { ...@@ -3881,20 +3901,22 @@ func TestTaskDiff(t *testing.T) {
} }
for i, c := range cases { for i, c := range cases {
actual, err := c.Old.Diff(c.New, c.Contextual) t.Run(c.Name, func(t *testing.T) {
if c.Error && err == nil { actual, err := c.Old.Diff(c.New, c.Contextual)
t.Fatalf("case %d: expected errored", i+1) if c.Error && err == nil {
} else if err != nil { t.Fatalf("case %d: expected errored", i+1)
if !c.Error { } else if err != nil {
t.Fatalf("case %d: errored %#v", i+1, err) if !c.Error {
} else { t.Fatalf("case %d: errored %#v", i+1, err)
continue } else {
return
}
} }
}
if !reflect.DeepEqual(actual, c.Expected) { if !reflect.DeepEqual(actual, c.Expected) {
t.Errorf("case %d: got:\n%#v\n want:\n%#v\n", t.Errorf("case %d: got:\n%#v\n want:\n%#v\n",
i+1, actual, c.Expected) i+1, actual, c.Expected)
} }
})
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment