Skip to content

Commit

Permalink
Improve the idiom for functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiusens committed Jun 9, 2015
1 parent 6515b6d commit dc6de7b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions partition/bootloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ type bootloaderType struct {
}

// Factory method that returns a new bootloader for the given partition
var getBootloader = getBootloaderImpl
var bootloader = bootloaderImpl

func getBootloaderImpl(p *Partition) (bootloader bootLoader, err error) {
func bootloaderImpl(p *Partition) (bootLoader, error) {
// try uboot
if uboot := newUboot(p); uboot != nil {
return uboot, nil
Expand Down
2 changes: 1 addition & 1 deletion partition/bootloader_grub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (s *PartitionTestSuite) TestGetBootVer(c *C) {
func (s *PartitionTestSuite) TestGetBootloaderWithGrub(c *C) {
s.makeFakeGrubEnv(c)
p := New()
bootloader, err := getBootloader(p)
bootloader, err := bootloader(p)
c.Assert(err, IsNil)
c.Assert(bootloader.Name(), Equals, bootloaderNameGrub)
}
Expand Down
12 changes: 6 additions & 6 deletions partition/bootloader_uboot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (s *PartitionTestSuite) TestUbootGetEnvVar(c *C) {
func (s *PartitionTestSuite) TestGetBootloaderWithUboot(c *C) {
s.makeFakeUbootEnv(c)
p := New()
bootloader, err := getBootloader(p)
bootloader, err := bootloader(p)
c.Assert(err, IsNil)
c.Assert(bootloader.Name(), Equals, bootloaderNameUboot)
}
Expand All @@ -168,7 +168,7 @@ func makeMockAssetsDir(c *C) {
func (s *PartitionTestSuite) TestHandleAssets(c *C) {
s.makeFakeUbootEnv(c)
p := New()
bootloader, err := getBootloader(p)
bootloader, err := bootloader(p)
c.Assert(err, IsNil)

// mock the hardwareYaml and the cacheDir
Expand Down Expand Up @@ -199,7 +199,7 @@ func (s *PartitionTestSuite) TestHandleAssets(c *C) {
func (s *PartitionTestSuite) TestHandleAssetsVerifyBootloader(c *C) {
s.makeFakeUbootEnv(c)
p := New()
bootloader, err := getBootloader(p)
bootloader, err := bootloader(p)
c.Assert(err, IsNil)

// mock the hardwareYaml and the cacheDir
Expand All @@ -213,7 +213,7 @@ func (s *PartitionTestSuite) TestHandleAssetsVerifyBootloader(c *C) {
func (s *PartitionTestSuite) TestHandleAssetsFailVerifyPartitionLayout(c *C) {
s.makeFakeUbootEnv(c)
p := New()
bootloader, err := getBootloader(p)
bootloader, err := bootloader(p)
c.Assert(err, IsNil)

// mock the hardwareYaml and the cacheDir
Expand All @@ -230,7 +230,7 @@ partition-layout: inplace
func (s *PartitionTestSuite) TestHandleAssetsNoHardwareYaml(c *C) {
s.makeFakeUbootEnv(c)
p := New()
bootloader, err := getBootloader(p)
bootloader, err := bootloader(p)
c.Assert(err, IsNil)

defaultCacheDir = c.MkDir()
Expand All @@ -241,7 +241,7 @@ func (s *PartitionTestSuite) TestHandleAssetsNoHardwareYaml(c *C) {
func (s *PartitionTestSuite) TestHandleAssetsBadHardwareYaml(c *C) {
s.makeFakeUbootEnv(c)
p := New()
bootloader, err := getBootloader(p)
bootloader, err := bootloader(p)
c.Assert(err, IsNil)

p.hardwareSpecFile = makeHardwareYaml(c, `
Expand Down
18 changes: 9 additions & 9 deletions partition/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type Interface interface {

// Returns the full path to the (mounted and writable)
// bootloader-specific boot directory.
GetBootloaderDir() string
BootloaderDir() string
}

// mountEntry represents a mount this package has created.
Expand Down Expand Up @@ -507,7 +507,7 @@ func (p *Partition) RunWithOther(option MountOption, f func(otherRoot string) (e
// SyncBootloaderFiles syncs the bootloader files
// FIXME: can we unexport this?
func (p *Partition) SyncBootloaderFiles() (err error) {
bootloader, err := getBootloader(p)
bootloader, err := bootloader(p)
if err != nil {
return err
}
Expand All @@ -524,7 +524,7 @@ func (p *Partition) ToggleNextBoot() (err error) {

// MarkBootSuccessful marks the boot as successful
func (p *Partition) MarkBootSuccessful() (err error) {
bootloader, err := getBootloader(p)
bootloader, err := bootloader(p)
if err != nil {
return err
}
Expand All @@ -535,7 +535,7 @@ func (p *Partition) MarkBootSuccessful() (err error) {
// IsNextBootOther return true if the next boot will use the other rootfs
// partition.
func (p *Partition) IsNextBootOther() bool {
bootloader, err := getBootloader(p)
bootloader, err := bootloader(p)
if err != nil {
return false
}
Expand Down Expand Up @@ -765,7 +765,7 @@ func (p *Partition) bindmountRequiredFilesystems() (err error) {
}

// add additional bootloader mounts, this is required for grub
bootloader, err := getBootloader(p)
bootloader, err := bootloader(p)
if err == nil && bootloader != nil {
for _, mount := range bootloader.AdditionalBindMounts() {
requiredChrootMounts = append(requiredChrootMounts, mount)
Expand Down Expand Up @@ -813,7 +813,7 @@ func (p *Partition) toggleBootloaderRootfs() (err error) {
return errors.New("System is not dual root")
}

bootloader, err := getBootloader(p)
bootloader, err := bootloader(p)
if err != nil {
return err
}
Expand All @@ -832,10 +832,10 @@ func (p *Partition) toggleBootloaderRootfs() (err error) {
return bootloader.HandleAssets()
}

// GetBootloaderDir returns the full path to the (mounted and writable)
// BootloaderDir returns the full path to the (mounted and writable)
// bootloader-specific boot directory.
func (p *Partition) GetBootloaderDir() string {
bootloader, err := getBootloader(p)
func (p *Partition) BootloaderDir() string {
bootloader, err := bootloader(p)
if err != nil {
return ""
}
Expand Down
8 changes: 4 additions & 4 deletions partition/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (s *PartitionTestSuite) TearDownTest(c *C) {
// always restore what we might have mocked away
runCommand = runCommandImpl
defaultCacheDir = realDefaultCacheDir
getBootloader = getBootloaderImpl
bootloader = bootloaderImpl

// grub vars
bootloaderGrubConfigFile = bootloaderGrubConfigFileReal
Expand Down Expand Up @@ -460,7 +460,7 @@ func (b *mockBootloader) BootDir() string {
func (s *PartitionTestSuite) TestToggleBootloaderRootfs(c *C) {
runCommand = mockRunCommand
b := &mockBootloader{}
getBootloader = func(p *Partition) (bootLoader, error) {
bootloader = func(p *Partition) (bootLoader, error) {
return b, nil
}

Expand All @@ -479,7 +479,7 @@ func (s *PartitionTestSuite) TestToggleBootloaderRootfs(c *C) {
func (s *PartitionTestSuite) TestMarkBootSuccessful(c *C) {
runCommand = mockRunCommand
b := &mockBootloader{}
getBootloader = func(p *Partition) (bootLoader, error) {
bootloader = func(p *Partition) (bootLoader, error) {
return b, nil
}

Expand All @@ -494,7 +494,7 @@ func (s *PartitionTestSuite) TestMarkBootSuccessful(c *C) {
func (s *PartitionTestSuite) TestSyncBootFiles(c *C) {
runCommand = mockRunCommand
b := &mockBootloader{}
getBootloader = func(p *Partition) (bootLoader, error) {
bootloader = func(p *Partition) (bootLoader, error) {
return b, nil
}

Expand Down
2 changes: 1 addition & 1 deletion provisioning/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func IsSideLoaded(bootloaderDir string) bool {

InstallYaml, err := parseInstallYaml(file)
if err != nil {
logger.LogError(err)
logger.Noticef("Kernel sideload cannot be read, assuming sideload: %s", err)
// file isn't parseable, so let's assume system is sideloaded
return true
}
Expand Down
2 changes: 1 addition & 1 deletion snappy/systemimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (s *SystemImagePart) SetActive(pb progress.Meter) (err error) {

// Install installs the snap
func (s *SystemImagePart) Install(pb progress.Meter, flags InstallFlags) (name string, err error) {
if provisioning.IsSideLoaded(s.partition.GetBootloaderDir()) {
if provisioning.IsSideLoaded(s.partition.BootloaderDir()) {
return "", ErrSideLoaded
}

Expand Down
4 changes: 2 additions & 2 deletions snappy/systemimage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (p *MockPartition) RunWithOther(option partition.MountOption, f func(otherR
// used by GetBootLoaderDir(), used to test sideload logic.
var tempBootDir string

func (p *MockPartition) GetBootloaderDir() string {
func (p *MockPartition) BootloaderDir() string {
return tempBootDir
}

Expand Down Expand Up @@ -399,7 +399,7 @@ options:
mockPartition := MockPartition{}
sp.partition = &mockPartition

bootDir := sp.partition.GetBootloaderDir()
bootDir := sp.partition.BootloaderDir()

sideLoaded := filepath.Join(bootDir, provisioning.InstallYamlFile)

Expand Down

0 comments on commit dc6de7b

Please sign in to comment.