Skip to content

Commit

Permalink
Move iaas_clients/factory into iaas_clients/vcenter_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
aramprice committed Jul 24, 2024
1 parent 9163d7f commit d3c44e3
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 58 deletions.
13 changes: 6 additions & 7 deletions commandparser/commandparserfakes/fake_manager_factory.go

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

9 changes: 4 additions & 5 deletions commandparser/construct.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -41,7 +40,7 @@ type VMPreparerFactory interface {
//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
Expand Down Expand Up @@ -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,
})

Expand Down
13 changes: 0 additions & 13 deletions iaas_cli/iaas_clients/factory/factory_suite_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion iaas_cli/iaas_clients/iaas_clients_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion iaas_cli/iaas_clients/vcenter_client_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion iaas_cli/iaas_clients/vcenter_govmomi_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vcenter_client_factory
package vcenter_manager

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

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vcenter_client_factory_test
package vcenter_manager_test

import (
"context"
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
9 changes: 4 additions & 5 deletions iaas_cli/iaas_clients/vcenter_manager/vcenter_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}

Expand Down

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

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

4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/cloudfoundry/stembuild/assets"
"github.com/cloudfoundry/stembuild/commandparser"
"github.com/cloudfoundry/stembuild/construct"
vcenterclientfactory "github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/factory"
"github.com/cloudfoundry/stembuild/iaas_cli/iaas_clients/vcenter_manager"
"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(), &construct.Factory{}, &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)
Expand Down

0 comments on commit d3c44e3

Please sign in to comment.