initialize: clean up TestProcessUnits()
This commit is contained in:
parent
dcaabe4d4a
commit
75ed8dacf9
@ -17,6 +17,7 @@
|
|||||||
package initialize
|
package initialize
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/coreos/coreos-cloudinit/config"
|
"github.com/coreos/coreos-cloudinit/config"
|
||||||
@ -59,72 +60,77 @@ func (tum *TestUnitManager) UnmaskUnit(u system.Unit) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestProcessUnits(t *testing.T) {
|
func TestProcessUnits(t *testing.T) {
|
||||||
tum := &TestUnitManager{}
|
tests := []struct {
|
||||||
units := []system.Unit{
|
units []system.Unit
|
||||||
|
|
||||||
|
result TestUnitManager
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
units: []system.Unit{
|
||||||
system.Unit{Unit: config.Unit{
|
system.Unit{Unit: config.Unit{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
Mask: true,
|
Mask: true,
|
||||||
}},
|
}},
|
||||||
}
|
},
|
||||||
if err := processUnits(units, "", tum); err != nil {
|
result: TestUnitManager{
|
||||||
t.Fatalf("unexpected error calling processUnits: %v", err)
|
masked: []string{"foo"},
|
||||||
}
|
},
|
||||||
if len(tum.masked) != 1 || tum.masked[0] != "foo" {
|
},
|
||||||
t.Errorf("expected foo to be masked, but found %v", tum.masked)
|
{
|
||||||
}
|
units: []system.Unit{
|
||||||
|
|
||||||
tum = &TestUnitManager{}
|
|
||||||
units = []system.Unit{
|
|
||||||
system.Unit{Unit: config.Unit{
|
system.Unit{Unit: config.Unit{
|
||||||
Name: "bar.network",
|
Name: "bar.network",
|
||||||
}},
|
}},
|
||||||
}
|
},
|
||||||
if err := processUnits(units, "", tum); err != nil {
|
result: TestUnitManager{
|
||||||
t.Fatalf("unexpected error calling processUnits: %v", err)
|
commands: map[string]string{
|
||||||
}
|
"systemd-networkd.service": "restart",
|
||||||
if _, ok := tum.commands["systemd-networkd.service"]; !ok {
|
},
|
||||||
t.Errorf("expected systemd-networkd.service to be reloaded!")
|
},
|
||||||
}
|
},
|
||||||
|
{
|
||||||
tum = &TestUnitManager{}
|
units: []system.Unit{
|
||||||
units = []system.Unit{
|
|
||||||
system.Unit{Unit: config.Unit{
|
system.Unit{Unit: config.Unit{
|
||||||
Name: "baz.service",
|
Name: "baz.service",
|
||||||
Content: "[Service]\nExecStart=/bin/true",
|
Content: "[Service]\nExecStart=/bin/true",
|
||||||
}},
|
}},
|
||||||
}
|
},
|
||||||
if err := processUnits(units, "", tum); err != nil {
|
result: TestUnitManager{
|
||||||
t.Fatalf("unexpected error calling processUnits: %v", err)
|
placed: []string{"baz.service"},
|
||||||
}
|
reload: true,
|
||||||
if len(tum.placed) != 1 || tum.placed[0] != "baz.service" {
|
},
|
||||||
t.Fatalf("expected baz.service to be written, but got %v", tum.placed)
|
},
|
||||||
}
|
{
|
||||||
|
units: []system.Unit{
|
||||||
tum = &TestUnitManager{}
|
|
||||||
units = []system.Unit{
|
|
||||||
system.Unit{Unit: config.Unit{
|
system.Unit{Unit: config.Unit{
|
||||||
Name: "locksmithd.service",
|
Name: "locksmithd.service",
|
||||||
Runtime: true,
|
Runtime: true,
|
||||||
}},
|
}},
|
||||||
}
|
},
|
||||||
if err := processUnits(units, "", tum); err != nil {
|
result: TestUnitManager{
|
||||||
t.Fatalf("unexpected error calling processUnits: %v", err)
|
unmasked: []string{"locksmithd.service"},
|
||||||
}
|
},
|
||||||
if len(tum.unmasked) != 1 || tum.unmasked[0] != "locksmithd.service" {
|
},
|
||||||
t.Fatalf("expected locksmithd.service to be unmasked, but got %v", tum.unmasked)
|
{
|
||||||
}
|
units: []system.Unit{
|
||||||
|
|
||||||
tum = &TestUnitManager{}
|
|
||||||
units = []system.Unit{
|
|
||||||
system.Unit{Unit: config.Unit{
|
system.Unit{Unit: config.Unit{
|
||||||
Name: "woof",
|
Name: "woof",
|
||||||
Enable: true,
|
Enable: true,
|
||||||
}},
|
}},
|
||||||
|
},
|
||||||
|
result: TestUnitManager{
|
||||||
|
enabled: []string{"woof"},
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
if err := processUnits(units, "", tum); err != nil {
|
|
||||||
t.Fatalf("unexpected error calling processUnits: %v", err)
|
for _, tt := range tests {
|
||||||
|
tum := &TestUnitManager{}
|
||||||
|
if err := processUnits(tt.units, "", tum); err != nil {
|
||||||
|
t.Errorf("bad error (%+v): want nil, got %s", tt.units, err)
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(tt.result, *tum) {
|
||||||
|
t.Errorf("bad result (%+v): want %+v, got %+v", tt.units, tt.result, tum)
|
||||||
}
|
}
|
||||||
if len(tum.enabled) != 1 || tum.enabled[0] != "woof" {
|
|
||||||
t.Fatalf("expected woof to be enabled, but got %v", tum.enabled)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user