Skip to content

Commit

Permalink
Rename packagers -> packager
Browse files Browse the repository at this point in the history
  • Loading branch information
aramprice committed Jul 24, 2024
1 parent 206cdac commit 73560c6
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 47 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/cloudfoundry/stembuild/commandparser"
vmconstructfactory "github.com/cloudfoundry/stembuild/construct/factory"
vcenterclientfactory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory"
"github.com/cloudfoundry/stembuild/package_stemcell/packagers"
"github.com/cloudfoundry/stembuild/package_stemcell/packager"
"github.com/cloudfoundry/stembuild/version"
)

Expand All @@ -35,7 +35,7 @@ func main() {
}

var gf commandparser.GlobalFlags
packageCmd := commandparser.NewPackageCommand(version.NewVersionGetter(), &packagers.Factory{}, &commandparser.PackageMessenger{Output: os.Stderr})
packageCmd := commandparser.NewPackageCommand(version.NewVersionGetter(), &packager.Factory{}, &commandparser.PackageMessenger{Output: os.Stderr})
packageCmd.GlobalFlags = &gf
constructCmd := commandparser.NewConstructCmd(context.Background(), &vmconstructfactory.VMConstructFactory{}, &vcenterclientfactory.ManagerFactory{}, &commandparser.ConstructValidator{}, &commandparser.ConstructCmdMessenger{OutputChannel: os.Stderr})
constructCmd.GlobalFlags = &gf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package packagers
package packager

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package packagers_test
package packager_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/cloudfoundry/stembuild/colorlogger"
"github.com/cloudfoundry/stembuild/package_stemcell/config"
"github.com/cloudfoundry/stembuild/package_stemcell/packagers"
"github.com/cloudfoundry/stembuild/package_stemcell/packager"
)

var _ = Describe("Factory", func() {
Expand All @@ -17,11 +17,11 @@ var _ = Describe("Factory", func() {
OutputDir: "/tmp/outputDir",
}

var packagerFactory *packagers.Factory
var packagerFactory *packager.Factory
var logger colorlogger.Logger

BeforeEach(func() {
packagerFactory = &packagers.Factory{}
packagerFactory = &packager.Factory{}
logger = colorlogger.New(0, false, GinkgoWriter)
})

Expand All @@ -35,8 +35,8 @@ var _ = Describe("Factory", func() {
actualPackager, err := packagerFactory.NewPackager(sourceConfig, outputConfig, logger)
Expect(err).NotTo(HaveOccurred())

Expect(actualPackager).To(BeAssignableToTypeOf(&packagers.VmdkPackager{}))
Expect(actualPackager).NotTo(BeAssignableToTypeOf(&packagers.VCenterPackager{}))
Expect(actualPackager).To(BeAssignableToTypeOf(&packager.VmdkPackager{}))
Expect(actualPackager).NotTo(BeAssignableToTypeOf(&packager.VCenterPackager{}))
})
})

Expand All @@ -52,8 +52,8 @@ var _ = Describe("Factory", func() {
actualPackager, err := packagerFactory.NewPackager(sourceConfig, outputConfig, logger)
Expect(err).NotTo(HaveOccurred())

Expect(actualPackager).To(BeAssignableToTypeOf(&packagers.VCenterPackager{}))
Expect(actualPackager).NotTo(BeAssignableToTypeOf(&packagers.VmdkPackager{}))
Expect(actualPackager).To(BeAssignableToTypeOf(&packager.VCenterPackager{}))
Expect(actualPackager).NotTo(BeAssignableToTypeOf(&packager.VmdkPackager{}))
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package packagers
package packager

import (
"archive/tar"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package packagers
package packager

import (
"archive/tar"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package packagers
package packager

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package packagers_test
package packager_test

import (
"archive/tar"
Expand All @@ -14,8 +14,8 @@ import (

"github.com/cloudfoundry/stembuild/filesystem"
"github.com/cloudfoundry/stembuild/package_stemcell/config"
"github.com/cloudfoundry/stembuild/package_stemcell/packagers"
"github.com/cloudfoundry/stembuild/package_stemcell/packagers/packagersfakes"
"github.com/cloudfoundry/stembuild/package_stemcell/packager"
"github.com/cloudfoundry/stembuild/package_stemcell/packager/packagerfakes"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -26,7 +26,7 @@ var _ = Describe("VcenterPackager", func() {
var outputDir string
var sourceConfig config.SourceConfig
var outputConfig config.OutputConfig
var fakeVcenterClient *packagersfakes.FakeIaasClient
var fakeVcenterClient *packagerfakes.FakeIaasClient

BeforeEach(func() {
// Revert to manual cleanup which fails non-catastrophically on windows
Expand All @@ -35,7 +35,7 @@ var _ = Describe("VcenterPackager", func() {

sourceConfig = config.SourceConfig{Password: "password", URL: "url", Username: "username", VmInventoryPath: "path/valid-vm-name"}
outputConfig = config.OutputConfig{Os: "2012R2", StemcellVersion: "1200.2", OutputDir: outputDir}
fakeVcenterClient = &packagersfakes.FakeIaasClient{}
fakeVcenterClient = &packagerfakes.FakeIaasClient{}
})

AfterEach(func() {
Expand All @@ -49,7 +49,7 @@ var _ = Describe("VcenterPackager", func() {
Context("ValidateSourceParameters", func() {
It("returns an error if the vCenter url is invalid", func() {
fakeVcenterClient.ValidateUrlReturns(errors.New("vcenter client url error"))
packager := packagers.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}
packager := packager.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}

err := packager.ValidateSourceParameters()

Expand All @@ -60,7 +60,7 @@ var _ = Describe("VcenterPackager", func() {
})
It("returns an error if the vCenter credentials are not valid", func() {
fakeVcenterClient.ValidateCredentialsReturns(errors.New("vcenter client credential error"))
packager := packagers.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}
packager := packager.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}

err := packager.ValidateSourceParameters()

Expand All @@ -71,7 +71,7 @@ var _ = Describe("VcenterPackager", func() {

It("returns an error if VM given does not exist ", func() {
fakeVcenterClient.FindVMReturns(errors.New("vcenter client vm error"))
packager := packagers.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}
packager := packager.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}

err := packager.ValidateSourceParameters()

Expand All @@ -80,7 +80,7 @@ var _ = Describe("VcenterPackager", func() {
Expect(err.Error()).To(Equal("vcenter client vm error"))
})
It("returns no error if all source parameters are valid", func() {
packager := packagers.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}
packager := packager.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}

err := packager.ValidateSourceParameters()

Expand All @@ -89,23 +89,23 @@ var _ = Describe("VcenterPackager", func() {
})
Context("ValidateFreeSpace", func() {
It("is a NOOP", func() {
packager := packagers.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}
packager := packager.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}
err := packager.ValidateFreeSpaceForPackage(&filesystem.OSFileSystem{})

Expect(err).To(Not(HaveOccurred()))
})
})

Describe("Package", func() {
var packager *packagers.VCenterPackager
var vcenterPackager *packager.VCenterPackager

AfterEach(func() {
_ = os.RemoveAll("./valid-vm-name")
_ = os.RemoveAll("image")
})

BeforeEach(func() {
packager = &packagers.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}
vcenterPackager = &packager.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}

fakeVcenterClient.ExportVMStub = func(vmInventoryPath string, destination string) error {
vmName := path.Base(vmInventoryPath)
Expand All @@ -119,11 +119,11 @@ var _ = Describe("VcenterPackager", func() {
})

It("creates a valid stemcell in the output directory", func() {
err := packager.Package()
err := vcenterPackager.Package()

Expect(err).To(Not(HaveOccurred()))
stemcellFilename := packagers.StemcellFilename(packager.OutputConfig.StemcellVersion, packager.OutputConfig.Os)
stemcellFile := filepath.Join(packager.OutputConfig.OutputDir, stemcellFilename)
stemcellFilename := packager.StemcellFilename(vcenterPackager.OutputConfig.StemcellVersion, vcenterPackager.OutputConfig.Os)
stemcellFile := filepath.Join(vcenterPackager.OutputConfig.OutputDir, stemcellFilename)
_, err = os.Stat(stemcellFile)

Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -186,7 +186,7 @@ stemcell_formats:
expectedDeviceList := []string{"ethernet-1", "floppy-8000", "floppy-9000"}
fakeVcenterClient.ListDevicesReturns(fullDeviceList, nil)

err := packager.Package()
err := vcenterPackager.Package()

Expect(err).NotTo(HaveOccurred())

Expand All @@ -202,7 +202,7 @@ stemcell_formats:
expectedDeviceList := []string{"cdrom-12", "cdrom-123"}
fakeVcenterClient.ListDevicesReturns(fullDeviceList, nil)

err := packager.Package()
err := vcenterPackager.Package()

Expect(err).NotTo(HaveOccurred())

Expand All @@ -216,20 +216,20 @@ stemcell_formats:
It("Throws an error if the VCenter client fails to list devices", func() {
fakeVcenterClient.ListDevicesReturns([]string{}, errors.New("some client error"))

err := packager.Package()
err := vcenterPackager.Package()
Expect(err).To(MatchError("some client error"))
})

It("Throws an error if the VCenter client fails to remove a device", func() {
fakeVcenterClient.ListDevicesReturns([]string{"floppy-8000"}, nil)
fakeVcenterClient.RemoveDeviceReturns(errors.New("some client error"))

err := packager.Package()
err := vcenterPackager.Package()
Expect(err).To(MatchError("some client error"))
})

It("Returns a error message if exporting the VM fails", func() {
packager := packagers.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}
packager := packager.VCenterPackager{SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: fakeVcenterClient}
fakeVcenterClient.ExportVMReturns(errors.New("some client error"))
err := packager.Package()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package packagers
package packager

import (
"archive/tar"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package packagers_test
package packager_test

import (
"testing"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package packagers_test
package packager_test

import (
"crypto/sha1"
Expand All @@ -15,21 +15,21 @@ import (
"github.com/cloudfoundry/stembuild/colorlogger"
mockfilesystem "github.com/cloudfoundry/stembuild/filesystem/mock"
"github.com/cloudfoundry/stembuild/package_stemcell/package_parameters"
"github.com/cloudfoundry/stembuild/package_stemcell/packagers"
"github.com/cloudfoundry/stembuild/package_stemcell/packager"
"github.com/cloudfoundry/stembuild/test/helpers"
)

var _ = Describe("VmdkPackager", func() {
var stembuildConfig package_parameters.VmdkPackageParameters
var vmdkPackager packagers.VmdkPackager
var vmdkPackager packager.VmdkPackager

BeforeEach(func() {
stembuildConfig = package_parameters.VmdkPackageParameters{
OSVersion: "2012R2",
Version: "1200.1",
}

vmdkPackager = packagers.VmdkPackager{
vmdkPackager = packager.VmdkPackager{
Stop: make(chan struct{}),
BuildOptions: stembuildConfig,
Logger: colorlogger.New(0, false, GinkgoWriter),
Expand All @@ -43,15 +43,15 @@ var _ = Describe("VmdkPackager", func() {
Expect(err).ToNot(HaveOccurred())
defer func() { _ = os.Remove(vmdk.Name()) }()

valid, err := packagers.IsValidVMDK(vmdk.Name())
valid, err := packager.IsValidVMDK(vmdk.Name())
Expect(err).To(BeNil())
Expect(valid).To(BeTrue())
})
})

Context("invalid vmdk file specified", func() {
It("should be invalid", func() {
valid, err := packagers.IsValidVMDK(filepath.Join("..", "out", "invalid"))
valid, err := packager.IsValidVMDK(filepath.Join("..", "out", "invalid"))
Expect(err).To(HaveOccurred())
Expect(valid).To(BeFalse())
})
Expand Down Expand Up @@ -142,7 +142,7 @@ var _ = Describe("VmdkPackager", func() {
Expect(err).ToNot(HaveOccurred())

testVmdkSize := vmdkFile.Size()
expectFreeSpace := uint64(testVmdkSize)*2 + (packagers.Gigabyte / 2)
expectFreeSpace := uint64(testVmdkSize)*2 + (packager.Gigabyte / 2)

directoryPath := filepath.Dir(vmdkPackager.BuildOptions.VMDKFile)
mockFileSystem.EXPECT().GetAvailableDiskSpace(directoryPath).Return(uint64(expectFreeSpace*2), nil).AnyTimes()
Expand All @@ -163,7 +163,7 @@ var _ = Describe("VmdkPackager", func() {
Expect(err).ToNot(HaveOccurred())

testVmdkSize := vmdkFile.Size()
expectFreeSpace := uint64(testVmdkSize)*2 + (packagers.Gigabyte / 2)
expectFreeSpace := uint64(testVmdkSize)*2 + (packager.Gigabyte / 2)

directoryPath := filepath.Dir(vmdkPackager.BuildOptions.VMDKFile)
mockFileSystem.EXPECT().GetAvailableDiskSpace(directoryPath).Return(uint64(expectFreeSpace/2), nil).AnyTimes()
Expand Down

0 comments on commit 73560c6

Please sign in to comment.