From aea5ca52526b106e1cf80515e70859c5c766bccc Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Tue, 6 May 2014 16:11:26 -0700 Subject: [PATCH] chore(initialize): code cleanups and gofmt --- initialize/etcd_test.go | 13 ++++++------- initialize/oem_test.go | 3 +-- system/file.go | 9 ++++----- system/systemd.go | 4 ++-- system/systemd_test.go | 19 +++++++++---------- 5 files changed, 22 insertions(+), 26 deletions(-) diff --git a/initialize/etcd_test.go b/initialize/etcd_test.go index 8ade9b8..ef78ca5 100644 --- a/initialize/etcd_test.go +++ b/initialize/etcd_test.go @@ -5,7 +5,6 @@ import ( "os" "os/exec" "path" - "syscall" "testing" ) @@ -60,15 +59,15 @@ Environment="ETCD_PEER_BIND_ADDR=127.0.0.1:7002" func TestEtcdEnvironmentWrittenToDisk(t *testing.T) { ec := EtcdEnvironment{ - "name": "node001", - "discovery": "http://disco.example.com/foobar", + "name": "node001", + "discovery": "http://disco.example.com/foobar", "peer-bind-addr": "127.0.0.1:7002", } dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-") if err != nil { t.Fatalf("Unable to create tempdir: %v", err) } - defer syscall.Rmdir(dir) + defer os.RemoveAll(dir) if err := WriteEtcdEnvironment(ec, dir); err != nil { t.Fatalf("Processing of EtcdEnvironment failed: %v", err) @@ -106,7 +105,7 @@ func TestEtcdEnvironmentWrittenToDiskDefaultToMachineID(t *testing.T) { if err != nil { 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)) 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 { - cmd := exec.Command("rm", "-rf", path) - return cmd.Run() + cmd := exec.Command("rm", "-rf", path) + return cmd.Run() } diff --git a/initialize/oem_test.go b/initialize/oem_test.go index 1ef10d4..85a69ad 100644 --- a/initialize/oem_test.go +++ b/initialize/oem_test.go @@ -4,7 +4,6 @@ import ( "io/ioutil" "os" "path" - "syscall" "testing" ) @@ -20,7 +19,7 @@ func TestOEMReleaseWrittenToDisk(t *testing.T) { if err != nil { t.Fatalf("Unable to create tempdir: %v", err) } - defer syscall.Rmdir(dir) + defer os.RemoveAll(dir) if err := WriteOEMRelease(&oem, dir); err != nil { t.Fatalf("Processing of EtcdEnvironment failed: %v", err) diff --git a/system/file.go b/system/file.go index 43cd4c2..d8d224f 100644 --- a/system/file.go +++ b/system/file.go @@ -11,10 +11,10 @@ import ( ) type File struct { - Encoding string - Content string - Owner string - Path string + Encoding string + Content string + Owner string + Path string RawFilePermissions string `yaml:"permissions"` } @@ -31,7 +31,6 @@ func (f *File) Permissions() (os.FileMode, error) { return os.FileMode(perm), nil } - func WriteFile(f *File) error { if f.Encoding != "" { return fmt.Errorf("Unable to write file with encoding %s", f.Encoding) diff --git a/system/systemd.go b/system/systemd.go index 9315638..5a80068 100644 --- a/system/systemd.go +++ b/system/systemd.go @@ -65,8 +65,8 @@ func PlaceUnit(u *Unit, dst string) error { } file := File{ - Path: dst, - Content: u.Content, + Path: dst, + Content: u.Content, RawFilePermissions: "0644", } diff --git a/system/systemd_test.go b/system/systemd_test.go index 4498456..201f1a0 100644 --- a/system/systemd_test.go +++ b/system/systemd_test.go @@ -4,15 +4,14 @@ import ( "io/ioutil" "os" "path" - "syscall" "testing" ) func TestPlaceNetworkUnit(t *testing.T) { u := Unit{ - Name: "50-eth0.network", - Runtime: true, - Content: `[Match] + Name: "50-eth0.network", + Runtime: true, + Content: `[Match] Name=eth47 [Network] @@ -24,7 +23,7 @@ Address=10.209.171.177/19 if err != nil { t.Fatalf("Unable to create tempdir: %v", err) } - defer syscall.Rmdir(dir) + defer os.RemoveAll(dir) dst := UnitDestination(&u, dir) 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) { u := Unit{ - Name: "media-state.mount", - Runtime: false, - Content: `[Mount] + Name: "media-state.mount", + Runtime: false, + Content: `[Mount] What=/dev/sdb1 Where=/media/state `, @@ -75,7 +74,7 @@ Where=/media/state if err != nil { t.Fatalf("Unable to create tempdir: %v", err) } - defer syscall.Rmdir(dir) + defer os.RemoveAll(dir) dst := UnitDestination(&u, dir) expectDst := path.Join(dir, "etc", "systemd", "system", "media-state.mount") @@ -115,7 +114,7 @@ func TestMachineID(t *testing.T) { if err != nil { 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)) ioutil.WriteFile(path.Join(dir, "etc", "machine-id"), []byte("node007\n"), os.FileMode(0444))