fix(etcd): fix runtime panic when etcd section is missing.
The etcd code tries to assign ee["name"] even when the map was never defined and assigning to an uninitialized map causes a panic.
This commit is contained in:
parent
f83ce07416
commit
ea6262f0ae
@ -31,6 +31,10 @@ func (ee EtcdEnvironment) String() (out string) {
|
|||||||
// Unit creates a Unit file drop-in for etcd, using any configured
|
// Unit creates a Unit file drop-in for etcd, using any configured
|
||||||
// options and adding a default MachineID if unset.
|
// options and adding a default MachineID if unset.
|
||||||
func (ee EtcdEnvironment) Unit(root string) (*system.Unit, error) {
|
func (ee EtcdEnvironment) Unit(root string) (*system.Unit, error) {
|
||||||
|
if ee == nil {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
if _, ok := ee["name"]; !ok {
|
if _, ok := ee["name"]; !ok {
|
||||||
if machineID := system.MachineID(root); machineID != "" {
|
if machineID := system.MachineID(root); machineID != "" {
|
||||||
ee["name"] = machineID
|
ee["name"] = machineID
|
||||||
|
@ -152,3 +152,15 @@ Environment="ETCD_NAME=node007"
|
|||||||
t.Fatalf("File has incorrect contents")
|
t.Fatalf("File has incorrect contents")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEtcdEnvironmentWhenNil(t *testing.T) {
|
||||||
|
// EtcdEnvironment will be a nil map if it wasn't in the yaml
|
||||||
|
var ee EtcdEnvironment
|
||||||
|
if ee != nil {
|
||||||
|
t.Fatalf("EtcdEnvironment is not nil")
|
||||||
|
}
|
||||||
|
u, err := ee.Unit("")
|
||||||
|
if u != nil || err != nil {
|
||||||
|
t.Fatalf("Unit returned a non-nil value for nil input")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user