diff --git a/commandparser/commandparserfakes/fake_manager_factory.go b/commandparser/commandparserfakes/fake_manager_factory.go index 7c25898e..7821612e 100644 --- a/commandparser/commandparserfakes/fake_manager_factory.go +++ b/commandparser/commandparserfakes/fake_manager_factory.go @@ -6,15 +6,14 @@ import ( "sync" "github.com/cloudfoundry/stembuild/commandparser" - vcenter_client_factory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory" "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager" ) type FakeManagerFactory struct { - SetConfigStub func(vcenter_client_factory.FactoryConfig) + SetConfigStub func(vcenter_manager.FactoryConfig) setConfigMutex sync.RWMutex setConfigArgsForCall []struct { - arg1 vcenter_client_factory.FactoryConfig + arg1 vcenter_manager.FactoryConfig } VCenterManagerStub func(context.Context) (*vcenter_manager.VCenterManager, error) vCenterManagerMutex sync.RWMutex @@ -33,10 +32,10 @@ type FakeManagerFactory struct { invocationsMutex sync.RWMutex } -func (fake *FakeManagerFactory) SetConfig(arg1 vcenter_client_factory.FactoryConfig) { +func (fake *FakeManagerFactory) SetConfig(arg1 vcenter_manager.FactoryConfig) { fake.setConfigMutex.Lock() fake.setConfigArgsForCall = append(fake.setConfigArgsForCall, struct { - arg1 vcenter_client_factory.FactoryConfig + arg1 vcenter_manager.FactoryConfig }{arg1}) stub := fake.SetConfigStub fake.recordInvocation("SetConfig", []interface{}{arg1}) @@ -52,13 +51,13 @@ func (fake *FakeManagerFactory) SetConfigCallCount() int { return len(fake.setConfigArgsForCall) } -func (fake *FakeManagerFactory) SetConfigCalls(stub func(vcenter_client_factory.FactoryConfig)) { +func (fake *FakeManagerFactory) SetConfigCalls(stub func(vcenter_manager.FactoryConfig)) { fake.setConfigMutex.Lock() defer fake.setConfigMutex.Unlock() fake.SetConfigStub = stub } -func (fake *FakeManagerFactory) SetConfigArgsForCall(i int) vcenter_client_factory.FactoryConfig { +func (fake *FakeManagerFactory) SetConfigArgsForCall(i int) vcenter_manager.FactoryConfig { fake.setConfigMutex.RLock() defer fake.setConfigMutex.RUnlock() argsForCall := fake.setConfigArgsForCall[i] diff --git a/commandparser/commandparserfakes/fake_packager_factory.go b/commandparser/commandparserfakes/fake_packager_factory.go index fdeffff6..42d7b836 100644 --- a/commandparser/commandparserfakes/fake_packager_factory.go +++ b/commandparser/commandparserfakes/fake_packager_factory.go @@ -10,18 +10,18 @@ import ( ) type FakePackagerFactory struct { - PackagerStub func(config.SourceConfig, config.OutputConfig, colorlogger.Logger) (commandparser.Packager, error) - packagerMutex sync.RWMutex - packagerArgsForCall []struct { + NewPackagerStub func(config.SourceConfig, config.OutputConfig, colorlogger.Logger) (commandparser.Packager, error) + newPackagerMutex sync.RWMutex + newPackagerArgsForCall []struct { arg1 config.SourceConfig arg2 config.OutputConfig arg3 colorlogger.Logger } - packagerReturns struct { + newPackagerReturns struct { result1 commandparser.Packager result2 error } - packagerReturnsOnCall map[int]struct { + newPackagerReturnsOnCall map[int]struct { result1 commandparser.Packager result2 error } @@ -29,18 +29,18 @@ type FakePackagerFactory struct { invocationsMutex sync.RWMutex } -func (fake *FakePackagerFactory) Packager(arg1 config.SourceConfig, arg2 config.OutputConfig, arg3 colorlogger.Logger) (commandparser.Packager, error) { - fake.packagerMutex.Lock() - ret, specificReturn := fake.packagerReturnsOnCall[len(fake.packagerArgsForCall)] - fake.packagerArgsForCall = append(fake.packagerArgsForCall, struct { +func (fake *FakePackagerFactory) NewPackager(arg1 config.SourceConfig, arg2 config.OutputConfig, arg3 colorlogger.Logger) (commandparser.Packager, error) { + fake.newPackagerMutex.Lock() + ret, specificReturn := fake.newPackagerReturnsOnCall[len(fake.newPackagerArgsForCall)] + fake.newPackagerArgsForCall = append(fake.newPackagerArgsForCall, struct { arg1 config.SourceConfig arg2 config.OutputConfig arg3 colorlogger.Logger }{arg1, arg2, arg3}) - stub := fake.PackagerStub - fakeReturns := fake.packagerReturns - fake.recordInvocation("Packager", []interface{}{arg1, arg2, arg3}) - fake.packagerMutex.Unlock() + stub := fake.NewPackagerStub + fakeReturns := fake.newPackagerReturns + fake.recordInvocation("NewPackager", []interface{}{arg1, arg2, arg3}) + fake.newPackagerMutex.Unlock() if stub != nil { return stub(arg1, arg2, arg3) } @@ -50,46 +50,46 @@ func (fake *FakePackagerFactory) Packager(arg1 config.SourceConfig, arg2 config. return fakeReturns.result1, fakeReturns.result2 } -func (fake *FakePackagerFactory) PackagerCallCount() int { - fake.packagerMutex.RLock() - defer fake.packagerMutex.RUnlock() - return len(fake.packagerArgsForCall) +func (fake *FakePackagerFactory) NewPackagerCallCount() int { + fake.newPackagerMutex.RLock() + defer fake.newPackagerMutex.RUnlock() + return len(fake.newPackagerArgsForCall) } -func (fake *FakePackagerFactory) PackagerCalls(stub func(config.SourceConfig, config.OutputConfig, colorlogger.Logger) (commandparser.Packager, error)) { - fake.packagerMutex.Lock() - defer fake.packagerMutex.Unlock() - fake.PackagerStub = stub +func (fake *FakePackagerFactory) NewPackagerCalls(stub func(config.SourceConfig, config.OutputConfig, colorlogger.Logger) (commandparser.Packager, error)) { + fake.newPackagerMutex.Lock() + defer fake.newPackagerMutex.Unlock() + fake.NewPackagerStub = stub } -func (fake *FakePackagerFactory) PackagerArgsForCall(i int) (config.SourceConfig, config.OutputConfig, colorlogger.Logger) { - fake.packagerMutex.RLock() - defer fake.packagerMutex.RUnlock() - argsForCall := fake.packagerArgsForCall[i] +func (fake *FakePackagerFactory) NewPackagerArgsForCall(i int) (config.SourceConfig, config.OutputConfig, colorlogger.Logger) { + fake.newPackagerMutex.RLock() + defer fake.newPackagerMutex.RUnlock() + argsForCall := fake.newPackagerArgsForCall[i] return argsForCall.arg1, argsForCall.arg2, argsForCall.arg3 } -func (fake *FakePackagerFactory) PackagerReturns(result1 commandparser.Packager, result2 error) { - fake.packagerMutex.Lock() - defer fake.packagerMutex.Unlock() - fake.PackagerStub = nil - fake.packagerReturns = struct { +func (fake *FakePackagerFactory) NewPackagerReturns(result1 commandparser.Packager, result2 error) { + fake.newPackagerMutex.Lock() + defer fake.newPackagerMutex.Unlock() + fake.NewPackagerStub = nil + fake.newPackagerReturns = struct { result1 commandparser.Packager result2 error }{result1, result2} } -func (fake *FakePackagerFactory) PackagerReturnsOnCall(i int, result1 commandparser.Packager, result2 error) { - fake.packagerMutex.Lock() - defer fake.packagerMutex.Unlock() - fake.PackagerStub = nil - if fake.packagerReturnsOnCall == nil { - fake.packagerReturnsOnCall = make(map[int]struct { +func (fake *FakePackagerFactory) NewPackagerReturnsOnCall(i int, result1 commandparser.Packager, result2 error) { + fake.newPackagerMutex.Lock() + defer fake.newPackagerMutex.Unlock() + fake.NewPackagerStub = nil + if fake.newPackagerReturnsOnCall == nil { + fake.newPackagerReturnsOnCall = make(map[int]struct { result1 commandparser.Packager result2 error }) } - fake.packagerReturnsOnCall[i] = struct { + fake.newPackagerReturnsOnCall[i] = struct { result1 commandparser.Packager result2 error }{result1, result2} @@ -98,8 +98,8 @@ func (fake *FakePackagerFactory) PackagerReturnsOnCall(i int, result1 commandpar func (fake *FakePackagerFactory) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() - fake.packagerMutex.RLock() - defer fake.packagerMutex.RUnlock() + fake.newPackagerMutex.RLock() + defer fake.newPackagerMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value diff --git a/commandparser/commandparserfakes/fake_vmpreparer_factory.go b/commandparser/commandparserfakes/fake_vmpreparer_factory.go index fd849216..d76efdf8 100644 --- a/commandparser/commandparserfakes/fake_vmpreparer_factory.go +++ b/commandparser/commandparserfakes/fake_vmpreparer_factory.go @@ -9,17 +9,17 @@ import ( ) type FakeVMPreparerFactory struct { - VMPreparerStub func(config.SourceConfig, commandparser.VCenterManager) (commandparser.VmConstruct, error) - vMPreparerMutex sync.RWMutex - vMPreparerArgsForCall []struct { + NewStub func(config.SourceConfig, commandparser.VCenterManager) (commandparser.VmConstruct, error) + newMutex sync.RWMutex + newArgsForCall []struct { arg1 config.SourceConfig arg2 commandparser.VCenterManager } - vMPreparerReturns struct { + newReturns struct { result1 commandparser.VmConstruct result2 error } - vMPreparerReturnsOnCall map[int]struct { + newReturnsOnCall map[int]struct { result1 commandparser.VmConstruct result2 error } @@ -27,17 +27,17 @@ type FakeVMPreparerFactory struct { invocationsMutex sync.RWMutex } -func (fake *FakeVMPreparerFactory) VMPreparer(arg1 config.SourceConfig, arg2 commandparser.VCenterManager) (commandparser.VmConstruct, error) { - fake.vMPreparerMutex.Lock() - ret, specificReturn := fake.vMPreparerReturnsOnCall[len(fake.vMPreparerArgsForCall)] - fake.vMPreparerArgsForCall = append(fake.vMPreparerArgsForCall, struct { +func (fake *FakeVMPreparerFactory) New(arg1 config.SourceConfig, arg2 commandparser.VCenterManager) (commandparser.VmConstruct, error) { + fake.newMutex.Lock() + ret, specificReturn := fake.newReturnsOnCall[len(fake.newArgsForCall)] + fake.newArgsForCall = append(fake.newArgsForCall, struct { arg1 config.SourceConfig arg2 commandparser.VCenterManager }{arg1, arg2}) - stub := fake.VMPreparerStub - fakeReturns := fake.vMPreparerReturns - fake.recordInvocation("VMPreparer", []interface{}{arg1, arg2}) - fake.vMPreparerMutex.Unlock() + stub := fake.NewStub + fakeReturns := fake.newReturns + fake.recordInvocation("New", []interface{}{arg1, arg2}) + fake.newMutex.Unlock() if stub != nil { return stub(arg1, arg2) } @@ -47,46 +47,46 @@ func (fake *FakeVMPreparerFactory) VMPreparer(arg1 config.SourceConfig, arg2 com return fakeReturns.result1, fakeReturns.result2 } -func (fake *FakeVMPreparerFactory) VMPreparerCallCount() int { - fake.vMPreparerMutex.RLock() - defer fake.vMPreparerMutex.RUnlock() - return len(fake.vMPreparerArgsForCall) +func (fake *FakeVMPreparerFactory) NewCallCount() int { + fake.newMutex.RLock() + defer fake.newMutex.RUnlock() + return len(fake.newArgsForCall) } -func (fake *FakeVMPreparerFactory) VMPreparerCalls(stub func(config.SourceConfig, commandparser.VCenterManager) (commandparser.VmConstruct, error)) { - fake.vMPreparerMutex.Lock() - defer fake.vMPreparerMutex.Unlock() - fake.VMPreparerStub = stub +func (fake *FakeVMPreparerFactory) NewCalls(stub func(config.SourceConfig, commandparser.VCenterManager) (commandparser.VmConstruct, error)) { + fake.newMutex.Lock() + defer fake.newMutex.Unlock() + fake.NewStub = stub } -func (fake *FakeVMPreparerFactory) VMPreparerArgsForCall(i int) (config.SourceConfig, commandparser.VCenterManager) { - fake.vMPreparerMutex.RLock() - defer fake.vMPreparerMutex.RUnlock() - argsForCall := fake.vMPreparerArgsForCall[i] +func (fake *FakeVMPreparerFactory) NewArgsForCall(i int) (config.SourceConfig, commandparser.VCenterManager) { + fake.newMutex.RLock() + defer fake.newMutex.RUnlock() + argsForCall := fake.newArgsForCall[i] return argsForCall.arg1, argsForCall.arg2 } -func (fake *FakeVMPreparerFactory) VMPreparerReturns(result1 commandparser.VmConstruct, result2 error) { - fake.vMPreparerMutex.Lock() - defer fake.vMPreparerMutex.Unlock() - fake.VMPreparerStub = nil - fake.vMPreparerReturns = struct { +func (fake *FakeVMPreparerFactory) NewReturns(result1 commandparser.VmConstruct, result2 error) { + fake.newMutex.Lock() + defer fake.newMutex.Unlock() + fake.NewStub = nil + fake.newReturns = struct { result1 commandparser.VmConstruct result2 error }{result1, result2} } -func (fake *FakeVMPreparerFactory) VMPreparerReturnsOnCall(i int, result1 commandparser.VmConstruct, result2 error) { - fake.vMPreparerMutex.Lock() - defer fake.vMPreparerMutex.Unlock() - fake.VMPreparerStub = nil - if fake.vMPreparerReturnsOnCall == nil { - fake.vMPreparerReturnsOnCall = make(map[int]struct { +func (fake *FakeVMPreparerFactory) NewReturnsOnCall(i int, result1 commandparser.VmConstruct, result2 error) { + fake.newMutex.Lock() + defer fake.newMutex.Unlock() + fake.NewStub = nil + if fake.newReturnsOnCall == nil { + fake.newReturnsOnCall = make(map[int]struct { result1 commandparser.VmConstruct result2 error }) } - fake.vMPreparerReturnsOnCall[i] = struct { + fake.newReturnsOnCall[i] = struct { result1 commandparser.VmConstruct result2 error }{result1, result2} @@ -95,8 +95,8 @@ func (fake *FakeVMPreparerFactory) VMPreparerReturnsOnCall(i int, result1 comman func (fake *FakeVMPreparerFactory) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() - fake.vMPreparerMutex.RLock() - defer fake.vMPreparerMutex.RUnlock() + fake.newMutex.RLock() + defer fake.newMutex.RUnlock() copiedInvocations := map[string][][]interface{}{} for key, value := range fake.invocations { copiedInvocations[key] = value diff --git a/commandparser/construct.go b/commandparser/construct.go index 4702c06a..b35d0084 100644 --- a/commandparser/construct.go +++ b/commandparser/construct.go @@ -13,7 +13,6 @@ import ( "github.com/vmware/govmomi/object" "github.com/cloudfoundry/stembuild/construct/config" - vcenterclientfactory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory" "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/guest_manager" "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager" ) @@ -35,13 +34,13 @@ type VCenterManager interface { //counterfeiter:generate . VMPreparerFactory type VMPreparerFactory interface { - VMPreparer(config config.SourceConfig, vCenterManager VCenterManager) (VmConstruct, error) + New(config config.SourceConfig, vCenterManager VCenterManager) (VmConstruct, error) } //counterfeiter:generate . ManagerFactory type ManagerFactory interface { VCenterManager(ctx context.Context) (*vcenter_manager.VCenterManager, error) - SetConfig(config vcenterclientfactory.FactoryConfig) + SetConfig(config vcenter_manager.FactoryConfig) } //counterfeiter:generate . ConstructCmdValidator @@ -139,12 +138,12 @@ func (p *ConstructCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interfac return subcommands.ExitFailure } - p.managerFactory.SetConfig(vcenterclientfactory.FactoryConfig{ + p.managerFactory.SetConfig(vcenter_manager.FactoryConfig{ VCenterServer: p.sourceConfig.VCenterUrl, Username: p.sourceConfig.VCenterUsername, Password: p.sourceConfig.VCenterPassword, - ClientCreator: &vcenterclientfactory.ClientCreator{}, - FinderCreator: &vcenterclientfactory.GovmomiFinderCreator{}, + ClientCreator: &vcenter_manager.ClientCreator{}, + FinderCreator: &vcenter_manager.GovmomiFinderCreator{}, RootCACertPath: p.sourceConfig.CaCertFile, }) @@ -154,7 +153,7 @@ func (p *ConstructCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interfac return subcommands.ExitFailure } - vmConstruct, err := p.prepFactory.VMPreparer(p.sourceConfig, vCenterManager) + vmConstruct, err := p.prepFactory.New(p.sourceConfig, vCenterManager) if err != nil { p.messenger.CannotPrepareVM(err) return subcommands.ExitFailure diff --git a/commandparser/construct_test.go b/commandparser/construct_test.go index 749587c6..80232d6f 100644 --- a/commandparser/construct_test.go +++ b/commandparser/construct_test.go @@ -157,7 +157,7 @@ var _ = Describe("construct", func() { fakeValidator = &commandparserfakes.FakeConstructCmdValidator{} fakeMessenger = &commandparserfakes.FakeConstructMessenger{} fakeManagerFactory = &commandparserfakes.FakeManagerFactory{} - fakeFactory.VMPreparerReturns(fakeVmConstruct, nil) + fakeFactory.NewReturns(fakeVmConstruct, nil) ConstrCmd = commandparser.NewConstructCmd(context.Background(), fakeFactory, fakeManagerFactory, fakeValidator, fakeMessenger) ConstrCmd.SetFlags(f) diff --git a/commandparser/package_stemcell.go b/commandparser/package_stemcell.go index 2b9967fd..1dce416e 100644 --- a/commandparser/package_stemcell.go +++ b/commandparser/package_stemcell.go @@ -23,7 +23,7 @@ type OSAndVersionGetter interface { //counterfeiter:generate . PackagerFactory type PackagerFactory interface { - Packager(sourceConfig config.SourceConfig, outputConfig config.OutputConfig, logger colorlogger.Logger) (Packager, error) + NewPackager(sourceConfig config.SourceConfig, outputConfig config.OutputConfig, logger colorlogger.Logger) (Packager, error) } //counterfeiter:generate . Packager @@ -130,7 +130,7 @@ func (p *PackageCmd) Execute(_ context.Context, f *flag.FlagSet, _ ...interface{ } logger := colorlogger.New(logLevel, p.GlobalFlags.Color, os.Stderr) - packager, err := p.packagerFactory.Packager(p.sourceConfig, p.outputConfig, logger) + packager, err := p.packagerFactory.NewPackager(p.sourceConfig, p.outputConfig, logger) if err != nil { p.packagerMessenger.CannotCreatePackager(err) return subcommands.ExitFailure diff --git a/commandparser/package_stemcell_test.go b/commandparser/package_stemcell_test.go index 2a4791f2..049cf63f 100644 --- a/commandparser/package_stemcell_test.go +++ b/commandparser/package_stemcell_test.go @@ -37,7 +37,7 @@ var _ = Describe("package_stemcell", func() { packager = new(commandparserfakes.FakePackager) packagerMessenger = new(commandparserfakes.FakePackagerMessenger) - packagerFactory.PackagerReturns(packager, nil) + packagerFactory.NewPackagerReturns(packager, nil) PkgCmd = commandparser.NewPackageCommand(oSAndVersionGetter, packagerFactory, packagerMessenger) PkgCmd.SetFlags(f) @@ -61,8 +61,8 @@ var _ = Describe("package_stemcell", func() { exitStatus := PkgCmd.Execute(context.Background(), f) Expect(exitStatus).To(Equal(subcommands.ExitSuccess)) - Expect(packagerFactory.PackagerCallCount()).To(Equal(1)) - actualSourceConfig, _, _ := packagerFactory.PackagerArgsForCall(0) + Expect(packagerFactory.NewPackagerCallCount()).To(Equal(1)) + actualSourceConfig, _, _ := packagerFactory.NewPackagerArgsForCall(0) Expect(actualSourceConfig.Vmdk).To(Equal("some_vmdk_file")) }) @@ -81,8 +81,8 @@ var _ = Describe("package_stemcell", func() { exitStatus := PkgCmd.Execute(context.Background(), f) Expect(exitStatus).To(Equal(subcommands.ExitSuccess)) - Expect(packagerFactory.PackagerCallCount()).To(Equal(1)) - actualSourceConfig, _, _ := packagerFactory.PackagerArgsForCall(0) + Expect(packagerFactory.NewPackagerCallCount()).To(Equal(1)) + actualSourceConfig, _, _ := packagerFactory.NewPackagerArgsForCall(0) Expect(actualSourceConfig.URL).To(Equal("https://vcenter.test")) Expect(actualSourceConfig.Username).To(Equal("test-user")) Expect(actualSourceConfig.Password).To(Equal("verysecure")) @@ -99,8 +99,8 @@ var _ = Describe("package_stemcell", func() { exitStatus := PkgCmd.Execute(context.Background(), f) Expect(exitStatus).To(Equal(subcommands.ExitSuccess)) - Expect(packagerFactory.PackagerCallCount()).To(Equal(1)) - _, actualOutputConfig, _ := packagerFactory.PackagerArgsForCall(0) + Expect(packagerFactory.NewPackagerCallCount()).To(Equal(1)) + _, actualOutputConfig, _ := packagerFactory.NewPackagerArgsForCall(0) Expect(actualOutputConfig.OutputDir).To(Equal("some_output_dir")) }) @@ -113,8 +113,8 @@ var _ = Describe("package_stemcell", func() { exitStatus := PkgCmd.Execute(context.Background(), f) Expect(exitStatus).To(Equal(subcommands.ExitSuccess)) - Expect(packagerFactory.PackagerCallCount()).To(Equal(1)) - _, actualOutputConfig, _ := packagerFactory.PackagerArgsForCall(0) + Expect(packagerFactory.NewPackagerCallCount()).To(Equal(1)) + _, actualOutputConfig, _ := packagerFactory.NewPackagerArgsForCall(0) Expect(actualOutputConfig.OutputDir).To(Equal("some_output_dir")) Expect(actualOutputConfig.StemcellVersion).To(Equal("2019.2")) Expect(actualOutputConfig.Os).To(Equal("2019")) @@ -131,8 +131,8 @@ var _ = Describe("package_stemcell", func() { exitStatus := PkgCmd.Execute(context.Background(), f) Expect(exitStatus).To(Equal(subcommands.ExitSuccess)) - Expect(packagerFactory.PackagerCallCount()).To(Equal(1)) - _, actualOutputConfig, _ := packagerFactory.PackagerArgsForCall(0) + Expect(packagerFactory.NewPackagerCallCount()).To(Equal(1)) + _, actualOutputConfig, _ := packagerFactory.NewPackagerArgsForCall(0) Expect(actualOutputConfig.StemcellVersion).To(Equal("1803.27.36")) Expect(oSAndVersionGetter.GetVersionWithPatchNumberCallCount()).To(Equal(1)) @@ -157,7 +157,7 @@ var _ = Describe("package_stemcell", func() { }) It("package is not called if the packager factory returns an error", func() { - packagerFactory.PackagerReturns(nil, errors.New("Couldn't make a packager!")) + packagerFactory.NewPackagerReturns(nil, errors.New("Couldn't make a packager!")) err := f.Parse(defaultArgs) Expect(err).ToNot(HaveOccurred()) @@ -165,7 +165,7 @@ var _ = Describe("package_stemcell", func() { exitStatus := PkgCmd.Execute(context.Background(), f) Expect(exitStatus).To(Equal(subcommands.ExitFailure)) - Expect(packagerFactory.PackagerCallCount()).To(Equal(1)) + Expect(packagerFactory.NewPackagerCallCount()).To(Equal(1)) Expect(packager.PackageCallCount()).To(Equal(0)) Expect(packagerMessenger.CannotCreatePackagerCallCount()).To(Equal(1)) diff --git a/construct/factory/vmconstruct_factory.go b/construct/factory.go similarity index 79% rename from construct/factory/vmconstruct_factory.go rename to construct/factory.go index 5138e650..f7ef364e 100644 --- a/construct/factory/vmconstruct_factory.go +++ b/construct/factory.go @@ -1,4 +1,4 @@ -package vmconstruct_factory +package construct import ( "context" @@ -7,7 +7,6 @@ import ( "github.com/pkg/errors" "github.com/cloudfoundry/stembuild/commandparser" - "github.com/cloudfoundry/stembuild/construct" "github.com/cloudfoundry/stembuild/construct/archive" "github.com/cloudfoundry/stembuild/construct/config" "github.com/cloudfoundry/stembuild/iaas_cli" @@ -17,14 +16,14 @@ import ( "github.com/cloudfoundry/stembuild/version" ) -type VMConstructFactory struct { +type Factory struct { } -func (f *VMConstructFactory) VMPreparer(config config.SourceConfig, vCenterManager commandparser.VCenterManager) (commandparser.VmConstruct, error) { +func (f *Factory) New(config config.SourceConfig, vCenterManager commandparser.VCenterManager) (commandparser.VmConstruct, error) { runner := &iaas_cli.GovcRunner{} client := iaas_clients.NewVcenterClient(config.VCenterUsername, config.VCenterPassword, config.VCenterUrl, config.CaCertFile, runner) - messenger := construct.NewMessenger(os.Stdout) + messenger := NewMessenger(os.Stdout) ctx := context.Background() err := vCenterManager.Login(ctx) @@ -44,7 +43,7 @@ func (f *VMConstructFactory) VMPreparer(config config.SourceConfig, vCenterManag return nil, err } - winRMManager := &construct.WinRMManager{ + winRMManager := &WinRMManager{ GuestManager: guestManager, Unarchiver: &archive.Zip{}, } @@ -53,7 +52,7 @@ func (f *VMConstructFactory) VMPreparer(config config.SourceConfig, vCenterManag winRmClientFactory := remotemanager.NewWinRmClientFactory(config.GuestVmIp, config.GuestVMUsername, config.GuestVMPassword) remoteManager := remotemanager.NewWinRM(config.GuestVmIp, config.GuestVMUsername, config.GuestVMPassword, winRmClientFactory) - vmConnectionValidator := &construct.WinRMConnectionValidator{ + vmConnectionValidator := &WinRMConnectionValidator{ RemoteManager: remoteManager, } @@ -63,9 +62,9 @@ func (f *VMConstructFactory) VMPreparer(config config.SourceConfig, vCenterManag rebootWaiter := remotemanager.NewRebootWaiter(rebootPoller, rebootChecker) - scriptExecutor := construct.NewScriptExecutor(remoteManager) + scriptExecutor := NewScriptExecutor(remoteManager) - return construct.NewVMConstruct( + return NewVMConstruct( ctx, remoteManager, config.GuestVMUsername, diff --git a/construct/factory/factory_suite_test.go b/construct/factory/factory_suite_test.go deleted file mode 100644 index 5e4b7e39..00000000 --- a/construct/factory/factory_suite_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package vmconstruct_factory - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestFactory(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "VmConstruct Factory Suite") -} diff --git a/construct/factory/vmconstruct_factory_test.go b/construct/factory_test.go similarity index 83% rename from construct/factory/vmconstruct_factory_test.go rename to construct/factory_test.go index 88f274bd..3f8a877c 100644 --- a/construct/factory/vmconstruct_factory_test.go +++ b/construct/factory_test.go @@ -1,4 +1,4 @@ -package vmconstruct_factory +package construct_test import ( . "github.com/onsi/ginkgo/v2" @@ -13,14 +13,14 @@ import ( var _ = Describe("Factory", func() { Describe("GetVMPreparer", func() { var ( - factory *VMConstructFactory + factory *construct.Factory ) BeforeEach(func() { - factory = &VMConstructFactory{} + factory = &construct.Factory{} }) - It("should return a VMPreparer", func() { + It("should return a New", func() { fakeVCenterManager := &commandparserfakes.FakeVCenterManager{} sourceConfig := config.SourceConfig{ @@ -33,7 +33,7 @@ var _ = Describe("Factory", func() { VmInventoryPath: "some-vm-inventory-path", } - vmPreparer, err := factory.VMPreparer(sourceConfig, fakeVCenterManager) + vmPreparer, err := factory.New(sourceConfig, fakeVCenterManager) Expect(err).ToNot(HaveOccurred()) Expect(vmPreparer).To(BeAssignableToTypeOf(&construct.VMConstruct{})) }) @@ -45,7 +45,7 @@ var _ = Describe("Factory", func() { fakeVCenterManager.LoginReturns(loginFailure) sourceConfig := config.SourceConfig{} - vmPreparer, err := factory.VMPreparer(sourceConfig, fakeVCenterManager) + vmPreparer, err := factory.New(sourceConfig, fakeVCenterManager) Expect(vmPreparer).To(BeNil()) Expect(err).To(HaveOccurred()) diff --git a/iaas_cli/iaas_clients/factory/factory_suite_test.go b/iaas_cli/iaas_clients/factory/factory_suite_test.go deleted file mode 100644 index 9158d9ab..00000000 --- a/iaas_cli/iaas_clients/factory/factory_suite_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package vcenter_client_factory_test - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestFactory(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Factory Suite") -} diff --git a/iaas_cli/iaas_clients/iaas_clients_suite_test.go b/iaas_cli/iaas_clients/iaas_clients_suite_test.go index 423c4e72..a605f61d 100644 --- a/iaas_cli/iaas_clients/iaas_clients_suite_test.go +++ b/iaas_cli/iaas_clients/iaas_clients_suite_test.go @@ -11,7 +11,7 @@ import ( . "github.com/onsi/gomega" "github.com/vmware/govmomi/object" - vcenterclientfactory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory" + vcenterclientfactory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager" ) func TestIaasClients(t *testing.T) { diff --git a/iaas_cli/iaas_clients/vcenter_client_contract_test.go b/iaas_cli/iaas_clients/vcenter_client_contract_test.go index 34a84ff1..e09ed142 100644 --- a/iaas_cli/iaas_clients/vcenter_client_contract_test.go +++ b/iaas_cli/iaas_clients/vcenter_client_contract_test.go @@ -9,7 +9,7 @@ import ( "time" "github.com/cloudfoundry/stembuild/iaas_cli" - vcenterclientfactory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory" + vcenterclientfactory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/iaas_cli/iaas_clients/vcenter_govmomi_contract_test.go b/iaas_cli/iaas_clients/vcenter_govmomi_contract_test.go index 3e4e3a72..29a09aee 100644 --- a/iaas_cli/iaas_clients/vcenter_govmomi_contract_test.go +++ b/iaas_cli/iaas_clients/vcenter_govmomi_contract_test.go @@ -7,8 +7,8 @@ import ( "path/filepath" "time" - vcenterclientfactory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory" "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/guest_manager" + vcenterclientfactory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" diff --git a/iaas_cli/iaas_clients/factory/vcenter_manager_factory.go b/iaas_cli/iaas_clients/vcenter_manager/factory.go similarity index 88% rename from iaas_cli/iaas_clients/factory/vcenter_manager_factory.go rename to iaas_cli/iaas_clients/vcenter_manager/factory.go index 44d25f8b..da108972 100644 --- a/iaas_cli/iaas_clients/factory/vcenter_manager_factory.go +++ b/iaas_cli/iaas_clients/vcenter_manager/factory.go @@ -1,4 +1,4 @@ -package vcenter_client_factory +package vcenter_manager import ( "context" @@ -10,8 +10,6 @@ import ( "github.com/vmware/govmomi/session" "github.com/vmware/govmomi/vim25" "github.com/vmware/govmomi/vim25/soap" - - "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager" ) //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate @@ -63,7 +61,7 @@ func (f *ManagerFactory) SetConfig(config FactoryConfig) { f.Config = config } -func (f *ManagerFactory) VCenterManager(ctx context.Context) (*vcenter_manager.VCenterManager, error) { +func (f *ManagerFactory) VCenterManager(ctx context.Context) (*VCenterManager, error) { govmomiClient, err := f.govmomiClient(ctx) if err != nil { @@ -72,7 +70,7 @@ func (f *ManagerFactory) VCenterManager(ctx context.Context) (*vcenter_manager.V finder := f.Config.FinderCreator.NewFinder(govmomiClient.Client, false) - return vcenter_manager.NewVCenterManager(govmomiClient, govmomiClient.Client, finder, f.Config.Username, f.Config.Password) + return NewVCenterManager(govmomiClient, govmomiClient.Client, finder, f.Config.Username, f.Config.Password) } diff --git a/iaas_cli/iaas_clients/factory/vcenter_manager_factory_test.go b/iaas_cli/iaas_clients/vcenter_manager/factory_test.go similarity index 70% rename from iaas_cli/iaas_clients/factory/vcenter_manager_factory_test.go rename to iaas_cli/iaas_clients/vcenter_manager/factory_test.go index 501b3a5e..8bb26c0d 100644 --- a/iaas_cli/iaas_clients/factory/vcenter_manager_factory_test.go +++ b/iaas_cli/iaas_clients/vcenter_manager/factory_test.go @@ -1,4 +1,4 @@ -package vcenter_client_factory_test +package vcenter_manager_test import ( "context" @@ -10,34 +10,33 @@ import ( "github.com/vmware/govmomi/find" "github.com/vmware/govmomi/vim25" - vcenterclientfactory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory" - "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory/factoryfakes" "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager" + "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager/vcenter_managerfakes" ) var _ = Describe("VcenterManagerFactory", func() { var ( - managerFactory *vcenterclientfactory.ManagerFactory + managerFactory *vcenter_manager.ManagerFactory ) BeforeEach(func() { - managerFactory = &vcenterclientfactory.ManagerFactory{} + managerFactory = &vcenter_manager.ManagerFactory{} }) Context("VCenterManager", func() { It("returns a vcenter manager", func() { fakeVimClient := &vim25.Client{} - fakeClientCreator := &factoryfakes.FakeVim25ClientCreator{} + fakeClientCreator := &vcenter_managerfakes.FakeVim25ClientCreator{} fakeClientCreator.NewClientReturns(fakeVimClient, nil) fakeFinder := &find.Finder{} - fakeFinderCreator := &factoryfakes.FakeFinderCreator{} + fakeFinderCreator := &vcenter_managerfakes.FakeFinderCreator{} fakeFinderCreator.NewFinderReturns(fakeFinder) - managerFactory.SetConfig(vcenterclientfactory.FactoryConfig{ + managerFactory.SetConfig(vcenter_manager.FactoryConfig{ VCenterServer: "example.com", Username: "user", Password: "pass", @@ -54,9 +53,9 @@ var _ = Describe("VcenterManagerFactory", func() { }) It("returns an error if the vcenter server cannot be parsed", func() { - fakeClientCreator := &factoryfakes.FakeVim25ClientCreator{} + fakeClientCreator := &vcenter_managerfakes.FakeVim25ClientCreator{} - managerFactory.SetConfig(vcenterclientfactory.FactoryConfig{ + managerFactory.SetConfig(vcenter_manager.FactoryConfig{ VCenterServer: " :", // make soap.ParseURL fail with Username: "user", Password: "pass", @@ -73,10 +72,10 @@ var _ = Describe("VcenterManagerFactory", func() { It("returns an error if a vim25 client cannot be created", func() { clientErr := errors.New("can't make a client") - fakeClientCreator := &factoryfakes.FakeVim25ClientCreator{} + fakeClientCreator := &vcenter_managerfakes.FakeVim25ClientCreator{} fakeClientCreator.NewClientReturns(nil, clientErr) - managerFactory.SetConfig(vcenterclientfactory.FactoryConfig{ + managerFactory.SetConfig(vcenter_manager.FactoryConfig{ VCenterServer: "example.com", Username: "user", Password: "pass", diff --git a/iaas_cli/iaas_clients/vcenter_manager/vcenter_manager_test.go b/iaas_cli/iaas_clients/vcenter_manager/vcenter_manager_test.go index 047cba63..2d0e33b4 100644 --- a/iaas_cli/iaas_clients/vcenter_manager/vcenter_manager_test.go +++ b/iaas_cli/iaas_clients/vcenter_manager/vcenter_manager_test.go @@ -11,7 +11,6 @@ import ( "github.com/vmware/govmomi/object" "github.com/vmware/govmomi/vim25" - vcenterclientfactory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory" "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/guest_manager" "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager" "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager/vcenter_managerfakes" @@ -136,16 +135,16 @@ var _ = Describe("VcenterManager", func() { inventoryPath := "/DC0/vm/DC0_H0_VM0" clonePath := "/DC0/vm/DC0_H0_VM0_NewClone" - factoryConfig := &vcenterclientfactory.FactoryConfig{ + factoryConfig := &vcenter_manager.FactoryConfig{ VCenterServer: "https://user:pass@127.0.0.1:8989/sdk", Username: "user", Password: "pass", - ClientCreator: &vcenterclientfactory.ClientCreator{}, - FinderCreator: &vcenterclientfactory.GovmomiFinderCreator{}, + ClientCreator: &vcenter_manager.ClientCreator{}, + FinderCreator: &vcenter_manager.GovmomiFinderCreator{}, RootCACertPath: CertPath, } - managerFactory := &vcenterclientfactory.ManagerFactory{ + managerFactory := &vcenter_manager.ManagerFactory{ Config: *factoryConfig, } diff --git a/iaas_cli/iaas_clients/factory/factoryfakes/fake_finder_creator.go b/iaas_cli/iaas_clients/vcenter_manager/vcenter_managerfakes/fake_finder_creator.go similarity index 94% rename from iaas_cli/iaas_clients/factory/factoryfakes/fake_finder_creator.go rename to iaas_cli/iaas_clients/vcenter_manager/vcenter_managerfakes/fake_finder_creator.go index e0c83604..1d55780c 100644 --- a/iaas_cli/iaas_clients/factory/factoryfakes/fake_finder_creator.go +++ b/iaas_cli/iaas_clients/vcenter_manager/vcenter_managerfakes/fake_finder_creator.go @@ -1,10 +1,10 @@ // Code generated by counterfeiter. DO NOT EDIT. -package factoryfakes +package vcenter_managerfakes import ( "sync" - vcenter_client_factory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory" + "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager" "github.com/vmware/govmomi/find" "github.com/vmware/govmomi/vim25" ) @@ -112,4 +112,4 @@ func (fake *FakeFinderCreator) recordInvocation(key string, args []interface{}) fake.invocations[key] = append(fake.invocations[key], args) } -var _ vcenter_client_factory.FinderCreator = new(FakeFinderCreator) +var _ vcenter_manager.FinderCreator = new(FakeFinderCreator) diff --git a/iaas_cli/iaas_clients/factory/factoryfakes/fake_vim25client_creator.go b/iaas_cli/iaas_clients/vcenter_manager/vcenter_managerfakes/fake_vim25client_creator.go similarity index 94% rename from iaas_cli/iaas_clients/factory/factoryfakes/fake_vim25client_creator.go rename to iaas_cli/iaas_clients/vcenter_manager/vcenter_managerfakes/fake_vim25client_creator.go index ad0b3953..0cb6d270 100644 --- a/iaas_cli/iaas_clients/factory/factoryfakes/fake_vim25client_creator.go +++ b/iaas_cli/iaas_clients/vcenter_manager/vcenter_managerfakes/fake_vim25client_creator.go @@ -1,11 +1,11 @@ // Code generated by counterfeiter. DO NOT EDIT. -package factoryfakes +package vcenter_managerfakes import ( "context" "sync" - vcenter_client_factory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory" + "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager" "github.com/vmware/govmomi/vim25" "github.com/vmware/govmomi/vim25/soap" ) @@ -118,4 +118,4 @@ func (fake *FakeVim25ClientCreator) recordInvocation(key string, args []interfac fake.invocations[key] = append(fake.invocations[key], args) } -var _ vcenter_client_factory.Vim25ClientCreator = new(FakeVim25ClientCreator) +var _ vcenter_manager.Vim25ClientCreator = new(FakeVim25ClientCreator) diff --git a/main.go b/main.go index adc92eb9..a2db5014 100644 --- a/main.go +++ b/main.go @@ -12,9 +12,9 @@ import ( "github.com/cloudfoundry/stembuild/assets" "github.com/cloudfoundry/stembuild/commandparser" - vmconstructfactory "github.com/cloudfoundry/stembuild/construct/factory" - vcenterclientfactory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory" - packagerfactory "github.com/cloudfoundry/stembuild/package_stemcell/factory" + "github.com/cloudfoundry/stembuild/construct" + "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager" + "github.com/cloudfoundry/stembuild/package_stemcell/packager" "github.com/cloudfoundry/stembuild/version" ) @@ -35,9 +35,9 @@ func main() { } var gf commandparser.GlobalFlags - packageCmd := commandparser.NewPackageCommand(version.NewVersionGetter(), &packagerfactory.PackagerFactory{}, &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 := commandparser.NewConstructCmd(context.Background(), &construct.Factory{}, &vcenter_manager.ManagerFactory{}, &commandparser.ConstructValidator{}, &commandparser.ConstructCmdMessenger{OutputChannel: os.Stderr}) constructCmd.GlobalFlags = &gf var commands = make([]subcommands.Command, 0) 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/factory/factory_suite_test.go b/package_stemcell/factory/factory_suite_test.go deleted file mode 100644 index d76791df..00000000 --- a/package_stemcell/factory/factory_suite_test.go +++ /dev/null @@ -1,13 +0,0 @@ -package factory_test - -import ( - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -func TestFactory(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Factory Suite") -} 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/factory/packager_factory.go b/package_stemcell/packager/factory.go similarity index 54% rename from package_stemcell/factory/packager_factory.go rename to package_stemcell/packager/factory.go index 83095c4b..a58f1b65 100644 --- a/package_stemcell/factory/packager_factory.go +++ b/package_stemcell/packager/factory.go @@ -1,4 +1,4 @@ -package factory +package packager import ( "errors" @@ -9,13 +9,11 @@ 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" - "github.com/cloudfoundry/stembuild/package_stemcell/packagers" ) -type PackagerFactory struct{} +type Factory struct{} -func (f *PackagerFactory) Packager(sourceConfig config.SourceConfig, outputConfig config.OutputConfig, logger colorlogger.Logger) (commandparser.Packager, error) { +func (f *Factory) NewPackager(sourceConfig config.SourceConfig, outputConfig config.OutputConfig, logger colorlogger.Logger) (commandparser.Packager, error) { source, err := sourceConfig.GetSource() if err != nil { return nil, err @@ -32,7 +30,7 @@ func (f *PackagerFactory) Packager(sourceConfig config.SourceConfig, outputConfi &iaas_cli.GovcRunner{}, ) - return &packagers.VCenterPackager{ + return &VCenterPackager{ SourceConfig: sourceConfig, OutputConfig: outputConfig, Client: client, @@ -40,19 +38,18 @@ func (f *PackagerFactory) Packager(sourceConfig config.SourceConfig, outputConfi }, nil case config.VMDK: options := - package_parameters.VmdkPackageParameters{} - - vmdkPackager := &packagers.VmdkPackager{ + config.VmdkOptions{ + VMDKFile: sourceConfig.Vmdk, + OSVersion: strings.ToUpper(outputConfig.Os), + Version: outputConfig.StemcellVersion, + OutputDir: outputConfig.OutputDir, + } + + return &VmdkPackager{ Stop: make(chan struct{}), BuildOptions: options, Logger: logger, - } - - vmdkPackager.BuildOptions.VMDKFile = sourceConfig.Vmdk - vmdkPackager.BuildOptions.OSVersion = strings.ToUpper(outputConfig.Os) - vmdkPackager.BuildOptions.Version = outputConfig.StemcellVersion - vmdkPackager.BuildOptions.OutputDir = outputConfig.OutputDir - return vmdkPackager, nil + }, nil default: return nil, errors.New("unable to determine packager") } diff --git a/package_stemcell/factory/packager_factory_test.go b/package_stemcell/packager/factory_test.go similarity index 69% rename from package_stemcell/factory/packager_factory_test.go rename to package_stemcell/packager/factory_test.go index 447a548b..6432ab91 100644 --- a/package_stemcell/factory/packager_factory_test.go +++ b/package_stemcell/packager/factory_test.go @@ -1,4 +1,4 @@ -package factory_test +package packager_test import ( . "github.com/onsi/ginkgo/v2" @@ -6,8 +6,7 @@ import ( "github.com/cloudfoundry/stembuild/colorlogger" "github.com/cloudfoundry/stembuild/package_stemcell/config" - "github.com/cloudfoundry/stembuild/package_stemcell/factory" - "github.com/cloudfoundry/stembuild/package_stemcell/packagers" + "github.com/cloudfoundry/stembuild/package_stemcell/packager" ) var _ = Describe("Factory", func() { @@ -18,11 +17,11 @@ var _ = Describe("Factory", func() { OutputDir: "/tmp/outputDir", } - var packagerFactory *factory.PackagerFactory + var packagerFactory *packager.Factory var logger colorlogger.Logger BeforeEach(func() { - packagerFactory = &factory.PackagerFactory{} + packagerFactory = &packager.Factory{} logger = colorlogger.New(0, false, GinkgoWriter) }) @@ -33,11 +32,11 @@ var _ = Describe("Factory", func() { Vmdk: "path/to/a/vmdk", } - actualPackager, err := packagerFactory.Packager(sourceConfig, outputConfig, logger) + 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{})) }) }) @@ -50,11 +49,11 @@ var _ = Describe("Factory", func() { VmInventoryPath: "some-vm-inventory-path", } - actualPackager, err := packagerFactory.Packager(sourceConfig, outputConfig, logger) + 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{})) }) }) @@ -65,7 +64,7 @@ var _ = Describe("Factory", func() { VmInventoryPath: "some-vm", } - packager, err := packagerFactory.Packager(sourceConfig, outputConfig, logger) + packager, err := packagerFactory.NewPackager(sourceConfig, outputConfig, logger) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(Equal("configuration provided for VMDK & vCenter sources")) Expect(packager).To(BeNil()) @@ -80,7 +79,7 @@ var _ = Describe("Factory", func() { URL: "some-url", } - packager, err := packagerFactory.Packager(sourceConfig, outputConfig, logger) + packager, err := packagerFactory.NewPackager(sourceConfig, outputConfig, logger) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(Equal("missing vCenter configurations")) Expect(packager).To(BeNil()) @@ -91,7 +90,7 @@ var _ = Describe("Factory", func() { It("returns an error", func() { sourceConfig := config.SourceConfig{} - packager, err := packagerFactory.Packager(sourceConfig, outputConfig, logger) + packager, err := packagerFactory.NewPackager(sourceConfig, outputConfig, logger) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(Equal("no configuration was provided")) Expect(packager).To(BeNil()) 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 98% rename from package_stemcell/packagers/vmdk_packager.go rename to package_stemcell/packager/vmdk_packager.go index 948afcc1..0360e78e 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" @@ -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/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 90% rename from package_stemcell/packagers/vmdk_packager_test.go rename to package_stemcell/packager/vmdk_packager_test.go index 806db368..8770e0fe 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" @@ -14,22 +14,22 @@ 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/config" + "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 stembuildConfig config.VmdkOptions + var vmdkPackager packager.VmdkPackager BeforeEach(func() { - stembuildConfig = package_parameters.VmdkPackageParameters{ + stembuildConfig = config.VmdkOptions{ OSVersion: "2012R2", 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()