Skip to content

Commit

Permalink
Move construct/factory package up to construct package
Browse files Browse the repository at this point in the history
  • Loading branch information
aramprice committed Jul 24, 2024
1 parent b45d53c commit 9163d7f
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 72 deletions.
78 changes: 39 additions & 39 deletions commandparser/commandparserfakes/fake_vmpreparer_factory.go

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

4 changes: 2 additions & 2 deletions commandparser/construct.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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
Expand Down Expand Up @@ -154,7 +154,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
Expand Down
2 changes: 1 addition & 1 deletion commandparser/construct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vmconstruct_factory
package construct

import (
"context"
Expand All @@ -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"
Expand All @@ -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)
Expand All @@ -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{},
}
Expand All @@ -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,
}

Expand All @@ -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,
Expand Down
13 changes: 0 additions & 13 deletions construct/factory/factory_suite_test.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vmconstruct_factory
package construct_test

import (
. "github.com/onsi/ginkgo/v2"
Expand All @@ -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{
Expand All @@ -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{}))
})
Expand All @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/cloudfoundry/stembuild/assets"
"github.com/cloudfoundry/stembuild/commandparser"
vmconstructfactory "github.com/cloudfoundry/stembuild/construct/factory"
"github.com/cloudfoundry/stembuild/construct"
vcenterclientfactory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory"
"github.com/cloudfoundry/stembuild/package_stemcell/packager"
"github.com/cloudfoundry/stembuild/version"
Expand All @@ -37,7 +37,7 @@ func main() {
var gf commandparser.GlobalFlags
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{}, &vcenterclientfactory.ManagerFactory{}, &commandparser.ConstructValidator{}, &commandparser.ConstructCmdMessenger{OutputChannel: os.Stderr})
constructCmd.GlobalFlags = &gf

var commands = make([]subcommands.Command, 0)
Expand Down

0 comments on commit 9163d7f

Please sign in to comment.