From b45d53c39586ebf7516e2802d641e8b4269abab5 Mon Sep 17 00:00:00 2001 From: aram price Date: Tue, 23 Jul 2024 17:48:15 -0700 Subject: [PATCH] Move package_parameters.VmdkPackageParameters -> config.VmdkOptions - remove unused `VmdkPackageParameters.CopyFrom()` method --- package_stemcell/config/vmdk_options.go | 8 + .../package_parameters/options_suite_test.go | 13 - .../vmdk_package_parameters.go | 25 -- .../vmdk_package_parameters_test.go | 227 ------------------ package_stemcell/packager/factory.go | 3 +- package_stemcell/packager/vmdk_packager.go | 4 +- .../packager/vmdk_packager_test.go | 6 +- 7 files changed, 14 insertions(+), 272 deletions(-) create mode 100644 package_stemcell/config/vmdk_options.go delete mode 100644 package_stemcell/package_parameters/options_suite_test.go delete mode 100644 package_stemcell/package_parameters/vmdk_package_parameters.go delete mode 100644 package_stemcell/package_parameters/vmdk_package_parameters_test.go diff --git a/package_stemcell/config/vmdk_options.go b/package_stemcell/config/vmdk_options.go new file mode 100644 index 00000000..7b98deee --- /dev/null +++ b/package_stemcell/config/vmdk_options.go @@ -0,0 +1,8 @@ +package config + +type VmdkOptions struct { + OSVersion string `yaml:"os_version"` + OutputDir string `yaml:"output_dir"` + Version string `yaml:"version"` + VMDKFile string `yaml:"vmdk_file"` +} diff --git a/package_stemcell/package_parameters/options_suite_test.go b/package_stemcell/package_parameters/options_suite_test.go deleted file mode 100644 index ba2324bd..00000000 --- a/package_stemcell/package_parameters/options_suite_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package package_parameters_test - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestStembuildOptions(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "VmdkPackageParameters Suite") -} diff --git a/package_stemcell/package_parameters/vmdk_package_parameters.go b/package_stemcell/package_parameters/vmdk_package_parameters.go deleted file mode 100644 index 7c675745..00000000 --- a/package_stemcell/package_parameters/vmdk_package_parameters.go +++ /dev/null @@ -1,25 +0,0 @@ -package package_parameters - -type VmdkPackageParameters struct { - OSVersion string `yaml:"os_version"` - OutputDir string `yaml:"output_dir"` - Version string `yaml:"version"` - VMDKFile string `yaml:"vmdk_file"` -} - -// Copy into `d` the values in `s` which are empty in `d`. -func (d *VmdkPackageParameters) CopyFrom(s VmdkPackageParameters) { - if d.OSVersion == "" { - d.OSVersion = s.OSVersion - } - - // ignore OutputDir from config file - - if d.Version == "" { - d.Version = s.Version - } - - if d.VMDKFile == "" { - d.VMDKFile = s.VMDKFile - } -} diff --git a/package_stemcell/package_parameters/vmdk_package_parameters_test.go b/package_stemcell/package_parameters/vmdk_package_parameters_test.go deleted file mode 100644 index dac39966..00000000 --- a/package_stemcell/package_parameters/vmdk_package_parameters_test.go +++ /dev/null @@ -1,227 +0,0 @@ -package package_parameters_test - -import ( - "fmt" - "math/rand" - - "github.com/cloudfoundry/stembuild/package_stemcell/package_parameters" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -var _ = Describe("VmdkPackageParameters", func() { - Context("CopyFrom", func() { - var ( - dest package_parameters.VmdkPackageParameters - src package_parameters.VmdkPackageParameters - ) - - BeforeEach(func() { - src = package_parameters.VmdkPackageParameters{} - dest = package_parameters.VmdkPackageParameters{} - }) - - JustBeforeEach(func() { - dest.CopyFrom(src) - }) - - Context("OSVersion", func() { - Context("when src specifies an OSVersion and dest does not", func() { - BeforeEach(func() { - src.OSVersion = fmt.Sprintf("banana%d.%d", rand.Intn(2000), rand.Intn(2000)) - }) - - It("copies src.OSVersion into dest.OSVersion", func() { - Expect(dest.OSVersion).To(Equal(src.OSVersion)) - }) - }) - - Context("when src specifies an OSVersion and dest specifies an OSVersion", func() { - var expectedDestOSVersion string - - BeforeEach(func() { - src.OSVersion = fmt.Sprintf("banana%d.%d", rand.Intn(2000), rand.Intn(2000)) - dest.OSVersion = fmt.Sprintf("banana%d.%d", rand.Intn(2000), rand.Intn(2000)) - expectedDestOSVersion = dest.OSVersion - }) - - It("retains dest.OSVersion's original value", func() { - Expect(dest.OSVersion).To(Equal(expectedDestOSVersion)) - }) - }) - - Context("when src does not specify an OSVersion and dest does not specify an OSVersion", func() { - It("should do nothing", func() { - Expect(dest.OSVersion).To(BeEmpty()) - }) - }) - - Context("when dest does specify a OSVersion and src does not specify a OSVersion", func() { - var expectedDestOSVersion string - - BeforeEach(func() { - dest.OSVersion = fmt.Sprintf("banana%d.%d", rand.Intn(2000), rand.Intn(2000)) - expectedDestOSVersion = dest.OSVersion - }) - It("should do nothing", func() { - Expect(dest.OSVersion).To(Equal(expectedDestOSVersion)) - }) - }) - }) - - Context("OutputDir", func() { - Context("when src specifies an OutputDir and dest does not", func() { - BeforeEach(func() { - src.OutputDir = fmt.Sprintf("foo%d/%d", rand.Intn(2000), rand.Intn(2000)) - }) - - It("does nothing", func() { - Expect(dest.OutputDir).To(Equal("")) - }) - }) - - Context("when src specifies an OutputDir and dest specifies an OutputDir", func() { - var expectedDestOutputDir string - - BeforeEach(func() { - src.OutputDir = fmt.Sprintf("foo%d/%d", rand.Intn(2000), rand.Intn(2000)) - dest.OutputDir = fmt.Sprintf("foo%d/%d", rand.Intn(2000), rand.Intn(2000)) - expectedDestOutputDir = dest.OutputDir - }) - - It("retains dest.OutputDir's original value", func() { - Expect(dest.OutputDir).To(Equal(expectedDestOutputDir)) - }) - }) - - Context("when src does not specify an OutputDir and dest does not specify an OutputDir", func() { - It("should do nothing", func() { - Expect(dest.OutputDir).To(BeEmpty()) - }) - }) - - Context("when dest does specify a OutputDir and src does not specify a OutputDir", func() { - var expectedDestOutputDir string - - BeforeEach(func() { - dest.OutputDir = fmt.Sprintf("foo%d/%d", rand.Intn(2000), rand.Intn(2000)) - expectedDestOutputDir = dest.OutputDir - }) - It("should do nothing", func() { - Expect(dest.OutputDir).To(Equal(expectedDestOutputDir)) - }) - }) - }) - - Context("Version", func() { - Context("when src specifies a version and dest does not", func() { - BeforeEach(func() { - src.Version = fmt.Sprintf("%d.%d", rand.Intn(2000), rand.Intn(2000)) - }) - - It("copies src.Version into dest.Version", func() { - Expect(dest.Version).To(Equal(src.Version)) - }) - }) - - Context("when src specifies a version and dest specifies a version", func() { - var expectedDestVersion string - - BeforeEach(func() { - src.Version = fmt.Sprintf("%d.%d", rand.Intn(2000), rand.Intn(2000)) - dest.Version = fmt.Sprintf("%d.%d", rand.Intn(2000), rand.Intn(2000)) - expectedDestVersion = dest.Version - }) - - It("retains dest.Version's original value", func() { - Expect(dest.Version).To(Equal(expectedDestVersion)) - }) - }) - - Context("when src does not specify a version and dest does not specify a version", func() { - It("should do nothing", func() { - Expect(dest.Version).To(BeEmpty()) - }) - }) - - Context("when dest does specify a Version and src does not specify a Version", func() { - var expectedDestVersion string - - BeforeEach(func() { - dest.Version = fmt.Sprintf("%d.%d", rand.Intn(2000), rand.Intn(2000)) - expectedDestVersion = dest.Version - }) - It("should do nothing", func() { - Expect(dest.Version).To(Equal(expectedDestVersion)) - }) - }) - }) - - Context("VMDKFile", func() { - Context("when src specifies an VMDKFile and dest does not", func() { - BeforeEach(func() { - src.VMDKFile = fmt.Sprintf("orange%d.vmdk", rand.Intn(2000)) - }) - - It("copies src.VMDKFile into dest.VMDKFile", func() { - Expect(dest.VMDKFile).To(Equal(src.VMDKFile)) - }) - }) - - Context("when src specifies a VMDKFile and dest specifies a VMDKFile", func() { - var expectedDestVMDKFile string - - BeforeEach(func() { - src.VMDKFile = fmt.Sprintf("orange%d.vmdk", rand.Intn(2000)) - dest.VMDKFile = fmt.Sprintf("orange%d.vmdk", rand.Intn(2000)) - expectedDestVMDKFile = dest.VMDKFile - }) - - It("retains dest.VMDKFile's original value", func() { - Expect(dest.VMDKFile).To(Equal(expectedDestVMDKFile)) - }) - }) - - Context("when src does not specify a VMDKFile and dest does not specify a VMDKFile", func() { - It("should do nothing", func() { - Expect(dest.VMDKFile).To(BeEmpty()) - }) - }) - - Context("when dest does specify a VMDKFile and src does not specify a VMDKFile", func() { - var expectedDestVMDKFile string - - BeforeEach(func() { - expectedDestVMDKFile = dest.VMDKFile - }) - It("should do nothing", func() { - Expect(dest.VMDKFile).To(Equal(expectedDestVMDKFile)) - }) - }) - }) - - Context("Multiple fields", func() { - Context("when some fields are set in src and another, somewhat overlapping, set of fields is set in dest", func() { - BeforeEach(func() { - dest.OutputDir = "needful" - dest.Version = "do" - dest.VMDKFile = "not" - src.OSVersion = "the" - src.OutputDir = "bear" - }) - - It("copies into dest only those fields which are empty in dest", func() { - expected := package_parameters.VmdkPackageParameters{ - OSVersion: "the", - OutputDir: "needful", - Version: "do", - VMDKFile: "not", - } - Expect(dest).To(Equal(expected)) - }) - }) - }) - }) - -}) diff --git a/package_stemcell/packager/factory.go b/package_stemcell/packager/factory.go index b418cfa5..a58f1b65 100644 --- a/package_stemcell/packager/factory.go +++ b/package_stemcell/packager/factory.go @@ -9,7 +9,6 @@ import ( "github.com/cloudfoundry/stembuild/iaas_cli" "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients" "github.com/cloudfoundry/stembuild/package_stemcell/config" - "github.com/cloudfoundry/stembuild/package_stemcell/package_parameters" ) type Factory struct{} @@ -39,7 +38,7 @@ func (f *Factory) NewPackager(sourceConfig config.SourceConfig, outputConfig con }, nil case config.VMDK: options := - package_parameters.VmdkPackageParameters{ + config.VmdkOptions{ VMDKFile: sourceConfig.Vmdk, OSVersion: strings.ToUpper(outputConfig.Os), Version: outputConfig.StemcellVersion, diff --git a/package_stemcell/packager/vmdk_packager.go b/package_stemcell/packager/vmdk_packager.go index 33c0468c..0360e78e 100644 --- a/package_stemcell/packager/vmdk_packager.go +++ b/package_stemcell/packager/vmdk_packager.go @@ -16,8 +16,8 @@ import ( "github.com/cloudfoundry/stembuild/colorlogger" "github.com/cloudfoundry/stembuild/filesystem" + "github.com/cloudfoundry/stembuild/package_stemcell/config" "github.com/cloudfoundry/stembuild/package_stemcell/ovftool" - "github.com/cloudfoundry/stembuild/package_stemcell/package_parameters" "github.com/cloudfoundry/stembuild/templates" ) @@ -30,7 +30,7 @@ type VmdkPackager struct { Sha1sum string tmpdir string Stop chan struct{} - BuildOptions package_parameters.VmdkPackageParameters + BuildOptions config.VmdkOptions Logger colorlogger.Logger } diff --git a/package_stemcell/packager/vmdk_packager_test.go b/package_stemcell/packager/vmdk_packager_test.go index 5bfc0045..8770e0fe 100644 --- a/package_stemcell/packager/vmdk_packager_test.go +++ b/package_stemcell/packager/vmdk_packager_test.go @@ -14,17 +14,17 @@ 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/config" "github.com/cloudfoundry/stembuild/package_stemcell/packager" "github.com/cloudfoundry/stembuild/test/helpers" ) var _ = Describe("VmdkPackager", func() { - var stembuildConfig package_parameters.VmdkPackageParameters + var stembuildConfig config.VmdkOptions var vmdkPackager packager.VmdkPackager BeforeEach(func() { - stembuildConfig = package_parameters.VmdkPackageParameters{ + stembuildConfig = config.VmdkOptions{ OSVersion: "2012R2", Version: "1200.1", }