From 73560c63b837f35edaa7092d3dc07ee00b2c7112 Mon Sep 17 00:00:00 2001 From: aram price Date: Tue, 23 Jul 2024 17:38:30 -0700 Subject: [PATCH] Rename `packagers` -> `packager` --- main.go | 4 +- .../{packagers => packager}/factory.go | 2 +- .../{packagers => packager}/factory_test.go | 16 ++++---- .../packager_utility.go | 2 +- .../packager_utility_test.go | 2 +- .../packagerfakes}/fake_iaas_client.go | 6 +-- .../vcenter_packager.go | 2 +- .../vcenter_packager_test.go | 40 +++++++++---------- .../{packagers => packager}/vmdk_packager.go | 2 +- .../vmdk_packager_suite_test.go | 2 +- .../vmdk_packager_test.go | 16 ++++---- 11 files changed, 47 insertions(+), 47 deletions(-) rename package_stemcell/{packagers => packager}/factory.go (98%) rename package_stemcell/{packagers => packager}/factory_test.go (84%) rename package_stemcell/{packagers => packager}/packager_utility.go (99%) rename package_stemcell/{packagers => packager}/packager_utility_test.go (99%) rename package_stemcell/{packagers/packagersfakes => packager/packagerfakes}/fake_iaas_client.go (99%) rename package_stemcell/{packagers => packager}/vcenter_packager.go (99%) rename package_stemcell/{packagers => packager}/vcenter_packager_test.go (80%) rename package_stemcell/{packagers => packager}/vmdk_packager.go (99%) rename package_stemcell/{packagers => packager}/vmdk_packager_suite_test.go (88%) rename package_stemcell/{packagers => packager}/vmdk_packager_test.go (93%) diff --git a/main.go b/main.go index 0b6c51f0..c9920438 100644 --- a/main.go +++ b/main.go @@ -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" ) @@ -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 diff --git a/package_stemcell/packagers/factory.go b/package_stemcell/packager/factory.go similarity index 98% rename from package_stemcell/packagers/factory.go rename to package_stemcell/packager/factory.go index bad2c4b5..b418cfa5 100644 --- a/package_stemcell/packagers/factory.go +++ b/package_stemcell/packager/factory.go @@ -1,4 +1,4 @@ -package packagers +package packager import ( "errors" diff --git a/package_stemcell/packagers/factory_test.go b/package_stemcell/packager/factory_test.go similarity index 84% rename from package_stemcell/packagers/factory_test.go rename to package_stemcell/packager/factory_test.go index 793cb45f..6432ab91 100644 --- a/package_stemcell/packagers/factory_test.go +++ b/package_stemcell/packager/factory_test.go @@ -1,4 +1,4 @@ -package packagers_test +package packager_test import ( . "github.com/onsi/ginkgo/v2" @@ -6,7 +6,7 @@ import ( "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() { @@ -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) }) @@ -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{})) }) }) @@ -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{})) }) }) diff --git a/package_stemcell/packagers/packager_utility.go b/package_stemcell/packager/packager_utility.go similarity index 99% rename from package_stemcell/packagers/packager_utility.go rename to package_stemcell/packager/packager_utility.go index 17ed40b9..ebef8224 100644 --- a/package_stemcell/packagers/packager_utility.go +++ b/package_stemcell/packager/packager_utility.go @@ -1,4 +1,4 @@ -package packagers +package packager import ( "archive/tar" diff --git a/package_stemcell/packagers/packager_utility_test.go b/package_stemcell/packager/packager_utility_test.go similarity index 99% rename from package_stemcell/packagers/packager_utility_test.go rename to package_stemcell/packager/packager_utility_test.go index d61a5a2f..42acb36e 100644 --- a/package_stemcell/packagers/packager_utility_test.go +++ b/package_stemcell/packager/packager_utility_test.go @@ -1,4 +1,4 @@ -package packagers +package packager import ( "archive/tar" diff --git a/package_stemcell/packagers/packagersfakes/fake_iaas_client.go b/package_stemcell/packager/packagerfakes/fake_iaas_client.go similarity index 99% rename from package_stemcell/packagers/packagersfakes/fake_iaas_client.go rename to package_stemcell/packager/packagerfakes/fake_iaas_client.go index 27190437..f0f897c0 100644 --- a/package_stemcell/packagers/packagersfakes/fake_iaas_client.go +++ b/package_stemcell/packager/packagerfakes/fake_iaas_client.go @@ -1,10 +1,10 @@ // Code generated by counterfeiter. DO NOT EDIT. -package packagersfakes +package packagerfakes import ( "sync" - "github.com/cloudfoundry/stembuild/package_stemcell/packagers" + "github.com/cloudfoundry/stembuild/package_stemcell/packager" ) type FakeIaasClient struct { @@ -545,4 +545,4 @@ func (fake *FakeIaasClient) recordInvocation(key string, args []interface{}) { fake.invocations[key] = append(fake.invocations[key], args) } -var _ packagers.IaasClient = new(FakeIaasClient) +var _ packager.IaasClient = new(FakeIaasClient) diff --git a/package_stemcell/packagers/vcenter_packager.go b/package_stemcell/packager/vcenter_packager.go similarity index 99% rename from package_stemcell/packagers/vcenter_packager.go rename to package_stemcell/packager/vcenter_packager.go index feb73c17..20ebaed1 100644 --- a/package_stemcell/packagers/vcenter_packager.go +++ b/package_stemcell/packager/vcenter_packager.go @@ -1,4 +1,4 @@ -package packagers +package packager import ( "errors" diff --git a/package_stemcell/packagers/vcenter_packager_test.go b/package_stemcell/packager/vcenter_packager_test.go similarity index 80% rename from package_stemcell/packagers/vcenter_packager_test.go rename to package_stemcell/packager/vcenter_packager_test.go index 825e0840..8f74ea0f 100644 --- a/package_stemcell/packagers/vcenter_packager_test.go +++ b/package_stemcell/packager/vcenter_packager_test.go @@ -1,4 +1,4 @@ -package packagers_test +package packager_test import ( "archive/tar" @@ -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" @@ -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 @@ -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() { @@ -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() @@ -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() @@ -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() @@ -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() @@ -89,7 +89,7 @@ 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())) @@ -97,7 +97,7 @@ var _ = Describe("VcenterPackager", func() { }) Describe("Package", func() { - var packager *packagers.VCenterPackager + var vcenterPackager *packager.VCenterPackager AfterEach(func() { _ = os.RemoveAll("./valid-vm-name") @@ -105,7 +105,7 @@ var _ = Describe("VcenterPackager", func() { }) 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) @@ -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()) @@ -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()) @@ -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()) @@ -216,7 +216,7 @@ 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")) }) @@ -224,12 +224,12 @@ stemcell_formats: 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() diff --git a/package_stemcell/packagers/vmdk_packager.go b/package_stemcell/packager/vmdk_packager.go similarity index 99% rename from package_stemcell/packagers/vmdk_packager.go rename to package_stemcell/packager/vmdk_packager.go index 948afcc1..33c0468c 100644 --- a/package_stemcell/packagers/vmdk_packager.go +++ b/package_stemcell/packager/vmdk_packager.go @@ -1,4 +1,4 @@ -package packagers +package packager import ( "archive/tar" diff --git a/package_stemcell/packagers/vmdk_packager_suite_test.go b/package_stemcell/packager/vmdk_packager_suite_test.go similarity index 88% rename from package_stemcell/packagers/vmdk_packager_suite_test.go rename to package_stemcell/packager/vmdk_packager_suite_test.go index 6c2b20b9..d105372f 100644 --- a/package_stemcell/packagers/vmdk_packager_suite_test.go +++ b/package_stemcell/packager/vmdk_packager_suite_test.go @@ -1,4 +1,4 @@ -package packagers_test +package packager_test import ( "testing" diff --git a/package_stemcell/packagers/vmdk_packager_test.go b/package_stemcell/packager/vmdk_packager_test.go similarity index 93% rename from package_stemcell/packagers/vmdk_packager_test.go rename to package_stemcell/packager/vmdk_packager_test.go index 806db368..5bfc0045 100644 --- a/package_stemcell/packagers/vmdk_packager_test.go +++ b/package_stemcell/packager/vmdk_packager_test.go @@ -1,4 +1,4 @@ -package packagers_test +package packager_test import ( "crypto/sha1" @@ -15,13 +15,13 @@ 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{ @@ -29,7 +29,7 @@ var _ = Describe("VmdkPackager", func() { Version: "1200.1", } - vmdkPackager = packagers.VmdkPackager{ + vmdkPackager = packager.VmdkPackager{ Stop: make(chan struct{}), BuildOptions: stembuildConfig, Logger: colorlogger.New(0, false, GinkgoWriter), @@ -43,7 +43,7 @@ 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()) }) @@ -51,7 +51,7 @@ var _ = Describe("VmdkPackager", func() { 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()) }) @@ -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() @@ -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()