Merge pull request #95 from philips/various-code-cleanups

chore(initialize): code cleanups and gofmt
This commit is contained in:
Brandon Philips 2014-05-06 16:19:35 -07:00
commit 85a473d972
5 changed files with 22 additions and 26 deletions

View File

@ -5,7 +5,6 @@ import (
"os" "os"
"os/exec" "os/exec"
"path" "path"
"syscall"
"testing" "testing"
) )
@ -60,15 +59,15 @@ Environment="ETCD_PEER_BIND_ADDR=127.0.0.1:7002"
func TestEtcdEnvironmentWrittenToDisk(t *testing.T) { func TestEtcdEnvironmentWrittenToDisk(t *testing.T) {
ec := EtcdEnvironment{ ec := EtcdEnvironment{
"name": "node001", "name": "node001",
"discovery": "http://disco.example.com/foobar", "discovery": "http://disco.example.com/foobar",
"peer-bind-addr": "127.0.0.1:7002", "peer-bind-addr": "127.0.0.1:7002",
} }
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-") dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
if err != nil { if err != nil {
t.Fatalf("Unable to create tempdir: %v", err) t.Fatalf("Unable to create tempdir: %v", err)
} }
defer syscall.Rmdir(dir) defer os.RemoveAll(dir)
if err := WriteEtcdEnvironment(ec, dir); err != nil { if err := WriteEtcdEnvironment(ec, dir); err != nil {
t.Fatalf("Processing of EtcdEnvironment failed: %v", err) t.Fatalf("Processing of EtcdEnvironment failed: %v", err)
@ -106,7 +105,7 @@ func TestEtcdEnvironmentWrittenToDiskDefaultToMachineID(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Unable to create tempdir: %v", err) t.Fatalf("Unable to create tempdir: %v", err)
} }
defer syscall.Rmdir(dir) defer os.RemoveAll(dir)
os.Mkdir(path.Join(dir, "etc"), os.FileMode(0755)) os.Mkdir(path.Join(dir, "etc"), os.FileMode(0755))
err = ioutil.WriteFile(path.Join(dir, "etc", "machine-id"), []byte("node007"), os.FileMode(0444)) err = ioutil.WriteFile(path.Join(dir, "etc", "machine-id"), []byte("node007"), os.FileMode(0444))
@ -134,6 +133,6 @@ Environment="ETCD_NAME=node007"
} }
func rmdir(path string) error { func rmdir(path string) error {
cmd := exec.Command("rm", "-rf", path) cmd := exec.Command("rm", "-rf", path)
return cmd.Run() return cmd.Run()
} }

View File

@ -4,7 +4,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
"syscall"
"testing" "testing"
) )
@ -20,7 +19,7 @@ func TestOEMReleaseWrittenToDisk(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Unable to create tempdir: %v", err) t.Fatalf("Unable to create tempdir: %v", err)
} }
defer syscall.Rmdir(dir) defer os.RemoveAll(dir)
if err := WriteOEMRelease(&oem, dir); err != nil { if err := WriteOEMRelease(&oem, dir); err != nil {
t.Fatalf("Processing of EtcdEnvironment failed: %v", err) t.Fatalf("Processing of EtcdEnvironment failed: %v", err)

View File

@ -11,10 +11,10 @@ import (
) )
type File struct { type File struct {
Encoding string Encoding string
Content string Content string
Owner string Owner string
Path string Path string
RawFilePermissions string `yaml:"permissions"` RawFilePermissions string `yaml:"permissions"`
} }
@ -31,7 +31,6 @@ func (f *File) Permissions() (os.FileMode, error) {
return os.FileMode(perm), nil return os.FileMode(perm), nil
} }
func WriteFile(f *File) error { func WriteFile(f *File) error {
if f.Encoding != "" { if f.Encoding != "" {
return fmt.Errorf("Unable to write file with encoding %s", f.Encoding) return fmt.Errorf("Unable to write file with encoding %s", f.Encoding)

View File

@ -65,8 +65,8 @@ func PlaceUnit(u *Unit, dst string) error {
} }
file := File{ file := File{
Path: dst, Path: dst,
Content: u.Content, Content: u.Content,
RawFilePermissions: "0644", RawFilePermissions: "0644",
} }

View File

@ -4,15 +4,14 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path"
"syscall"
"testing" "testing"
) )
func TestPlaceNetworkUnit(t *testing.T) { func TestPlaceNetworkUnit(t *testing.T) {
u := Unit{ u := Unit{
Name: "50-eth0.network", Name: "50-eth0.network",
Runtime: true, Runtime: true,
Content: `[Match] Content: `[Match]
Name=eth47 Name=eth47
[Network] [Network]
@ -24,7 +23,7 @@ Address=10.209.171.177/19
if err != nil { if err != nil {
t.Fatalf("Unable to create tempdir: %v", err) t.Fatalf("Unable to create tempdir: %v", err)
} }
defer syscall.Rmdir(dir) defer os.RemoveAll(dir)
dst := UnitDestination(&u, dir) dst := UnitDestination(&u, dir)
expectDst := path.Join(dir, "run", "systemd", "network", "50-eth0.network") expectDst := path.Join(dir, "run", "systemd", "network", "50-eth0.network")
@ -63,9 +62,9 @@ Address=10.209.171.177/19
func TestPlaceMountUnit(t *testing.T) { func TestPlaceMountUnit(t *testing.T) {
u := Unit{ u := Unit{
Name: "media-state.mount", Name: "media-state.mount",
Runtime: false, Runtime: false,
Content: `[Mount] Content: `[Mount]
What=/dev/sdb1 What=/dev/sdb1
Where=/media/state Where=/media/state
`, `,
@ -75,7 +74,7 @@ Where=/media/state
if err != nil { if err != nil {
t.Fatalf("Unable to create tempdir: %v", err) t.Fatalf("Unable to create tempdir: %v", err)
} }
defer syscall.Rmdir(dir) defer os.RemoveAll(dir)
dst := UnitDestination(&u, dir) dst := UnitDestination(&u, dir)
expectDst := path.Join(dir, "etc", "systemd", "system", "media-state.mount") expectDst := path.Join(dir, "etc", "systemd", "system", "media-state.mount")
@ -115,7 +114,7 @@ func TestMachineID(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Unable to create tempdir: %v", err) t.Fatalf("Unable to create tempdir: %v", err)
} }
defer syscall.Rmdir(dir) defer os.RemoveAll(dir)
os.Mkdir(path.Join(dir, "etc"), os.FileMode(0755)) os.Mkdir(path.Join(dir, "etc"), os.FileMode(0755))
ioutil.WriteFile(path.Join(dir, "etc", "machine-id"), []byte("node007\n"), os.FileMode(0444)) ioutil.WriteFile(path.Join(dir, "etc", "machine-id"), []byte("node007\n"), os.FileMode(0444))