fleet: refactor config

- Explicitly specify all of the valid options for fleet
- Seperate the config from Units()
- Add YAML tags for the fields
This commit is contained in:
Alex Crawford
2014-09-21 19:28:04 -07:00
parent c255739a93
commit 9454522033
7 changed files with 83 additions and 93 deletions

26
system/fleet.go Normal file
View File

@@ -0,0 +1,26 @@
package system
import (
"github.com/coreos/coreos-cloudinit/config"
)
// Fleet is a top-level structure which embeds its underlying configuration,
// config.Fleet, and provides the system-specific Unit().
type Fleet struct {
config.Fleet
}
// Units generates a Unit file drop-in for fleet, if any fleet options were
// configured in cloud-config
func (fe Fleet) Units(_ string) ([]Unit, error) {
content := dropinContents(fe.Fleet)
if content == "" {
return nil, nil
}
return []Unit{{
Name: "fleet.service",
Runtime: true,
DropIn: true,
Content: content,
}}, nil
}

41
system/fleet_test.go Normal file
View File

@@ -0,0 +1,41 @@
package system
import (
"reflect"
"testing"
"github.com/coreos/coreos-cloudinit/config"
)
func TestFleetUnits(t *testing.T) {
for _, tt := range []struct {
config config.Fleet
units []Unit
}{
{
config.Fleet{},
nil,
},
{
config.Fleet{
PublicIP: "12.34.56.78",
},
[]Unit{{
Name: "fleet.service",
Content: `[Service]
Environment="FLEET_PUBLIC_IP=12.34.56.78"
`,
Runtime: true,
DropIn: true,
}},
},
} {
units, err := Fleet{tt.config}.Units("")
if err != nil {
t.Errorf("bad error (%q): want %q, got %q", tt.config, nil, err)
}
if !reflect.DeepEqual(units, tt.units) {
t.Errorf("bad units (%q): want %q, got %q", tt.config, tt.units, units)
}
}
}