Skip to content

Commit 4a9c0c4

Browse files
committed
stembuild: move integration-ish iaas_cli tests to integration
- some tests under iaas_cli/ can be run locally but not when mixed with specs which require access to vCenter or similar setup - moves tests which require external resources under integration/iaas_cli/ - moves test-contract-stembuild-linux task testing into integration task
1 parent d6d6fe8 commit 4a9c0c4

File tree

18 files changed

+297
-318
lines changed

18 files changed

+297
-318
lines changed

ci/tasks/test-contract-stembuild-linux/run.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

ci/tasks/test-contract-stembuild-linux/task.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

ci/tasks/test-contract-stembuild-windows/run.ps1

Lines changed: 0 additions & 19 deletions
This file was deleted.

ci/tasks/test-contract-stembuild-windows/task.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

ci/tasks/test-integration-stembuild-linux/run.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ VM_NAME=$(cat integration-vm-name/name)
2323

2424
echo "Using Existing VM IP/Name: ${TARGET_VM_IP}/${VM_NAME}"
2525

26+
echo "install vcsim for vCenter manager and client contract integration tests"
27+
go -C govmomi/vcsim install
28+
2629
pushd "${ROOT_DIR}/stemcell-builder/stembuild"
2730
echo '***Test Stembuild Code***'
2831
make integration

stembuild/Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ clean :
3434
rm -rf assets/StemcellAutomation.zip out/*
3535

3636
units : stubbed-stemcell-automation-zip
37-
go run github.com/onsi/ginkgo/v2/ginkgo run -r --randomize-all --randomize-suites --keep-going --skip-package integration,iaas_cli
38-
39-
iaas_cli :
40-
go run github.com/onsi/ginkgo/v2/ginkgo run -r --randomize-all --randomize-suites --keep-going --flake-attempts 2 iaas_cli
37+
go run github.com/onsi/ginkgo/v2/ginkgo run -r --randomize-all --randomize-suites --keep-going --skip-package integration
4138

4239
integration : stubbed-stemcell-automation-zip
4340
go run github.com/onsi/ginkgo/v2/ginkgo run -r --timeout 3h -vv --randomize-all --keep-going --flake-attempts 2 integration
Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package iaas_cli_test
22

33
import (
4-
"fmt"
5-
"os"
64
"testing"
75

86
. "github.com/onsi/ginkgo/v2"
@@ -13,18 +11,3 @@ func TestIaasCli(t *testing.T) {
1311
RegisterFailHandler(Fail)
1412
RunSpecs(t, "IaasCli Suite")
1513
}
16-
17-
var targetVMPath string
18-
var vCenterCredentialUrl string
19-
20-
var _ = BeforeSuite(func() {
21-
vCenterCredentialUrl = os.Getenv("VCENTER_ADMIN_CREDENTIAL_URL")
22-
Expect(vCenterCredentialUrl).NotTo(Equal(""), "VCENTER_ADMIN_CREDENTIAL_URL is required")
23-
24-
vmFolder := os.Getenv("VM_FOLDER")
25-
Expect(vmFolder).NotTo(Equal(""), "VM_FOLDER is required")
26-
vmName := os.Getenv("PACKAGE_TEST_VM_NAME")
27-
Expect(vmName).NotTo(Equal(""), "PACKAGE_TEST_VM_NAME is required")
28-
29-
targetVMPath = fmt.Sprintf("%s/%s", vmFolder, vmName)
30-
})
Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,13 @@
11
package iaas_clients
22

33
import (
4-
"context"
5-
"fmt"
6-
"os"
74
"testing"
8-
"time"
95

10-
"github.com/google/uuid"
116
. "github.com/onsi/ginkgo/v2"
127
. "github.com/onsi/gomega"
13-
"github.com/vmware/govmomi/object"
14-
15-
vcenterclientfactory "github.com/cloudfoundry/bosh-windows-stemcell-builder/stembuild/iaas_cli/iaas_clients/vcenter_manager"
168
)
179

1810
func TestIaasClients(t *testing.T) {
1911
RegisterFailHandler(Fail)
2012
RunSpecs(t, "IaasClients Suite")
2113
}
22-
23-
const (
24-
VcenterUrl = "VCENTER_BASE_URL"
25-
VcenterUsername = "VCENTER_USERNAME"
26-
VcenterPassword = "VCENTER_PASSWORD"
27-
VcenterCACert = "VCENTER_CA_CERT"
28-
VmFolder = "VM_FOLDER"
29-
TestVmName = "CONTRACT_TEST_VM_NAME"
30-
TestVmPassword = "CONTRACT_TEST_VM_PASSWORD"
31-
TestVmUsername = "CONTRACT_TEST_VM_USERNAME"
32-
)
33-
34-
var TestVmPath string
35-
var VM *object.VirtualMachine
36-
var CTX context.Context
37-
var _ = BeforeSuite(func() {
38-
39-
managerFactory := &vcenterclientfactory.ManagerFactory{Config: vcenterclientfactory.FactoryConfig{
40-
VCenterServer: envMustExist(VcenterUrl),
41-
Username: envMustExist(VcenterUsername),
42-
Password: envMustExist(VcenterPassword),
43-
ClientCreator: &vcenterclientfactory.ClientCreator{},
44-
FinderCreator: &vcenterclientfactory.GovmomiFinderCreator{},
45-
},
46-
}
47-
48-
CTX = context.TODO()
49-
50-
vCenterManager, err := managerFactory.VCenterManager(CTX)
51-
Expect(err).ToNot(HaveOccurred())
52-
53-
err = vCenterManager.Login(CTX)
54-
Expect(err).ToNot(HaveOccurred())
55-
56-
vmFolder := envMustExist(VmFolder)
57-
testVmName := envMustExist(TestVmName)
58-
testVmPath := fmt.Sprintf("%s/%s", vmFolder, testVmName)
59-
60-
vmToClone, err := vCenterManager.FindVM(CTX, testVmPath)
61-
Expect(err).ToNot(HaveOccurred())
62-
63-
TestVmPath = testVmPath + fmt.Sprintf("%s", uuid.New())[0:8] //nolint:staticcheck
64-
65-
err = vCenterManager.CloneVM(CTX, vmToClone, TestVmPath)
66-
Expect(err).ToNot(HaveOccurred())
67-
68-
time.Sleep(30 * time.Second)
69-
70-
VM, err = vCenterManager.FindVM(CTX, TestVmPath)
71-
Expect(err).ToNot(HaveOccurred())
72-
73-
})
74-
75-
var _ = AfterSuite(func() {
76-
77-
if VM != nil {
78-
task, err := VM.PowerOff(CTX)
79-
Expect(err).ToNot(HaveOccurred())
80-
err = task.WaitEx(CTX)
81-
Expect(err).ToNot(HaveOccurred())
82-
83-
task, err = VM.Destroy(CTX)
84-
Expect(err).ToNot(HaveOccurred())
85-
err = task.WaitEx(CTX)
86-
Expect(err).ToNot(HaveOccurred())
87-
}
88-
})
89-
90-
func envMustExist(variableName string) string {
91-
result := os.Getenv(variableName)
92-
if result == "" {
93-
Fail(fmt.Sprintf("%s must be set", variableName))
94-
}
95-
96-
return result
97-
}
Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
package vcenter_manager_test
22

33
import (
4-
"os"
5-
"os/exec"
6-
"path/filepath"
7-
"runtime"
84
"testing"
9-
"time"
105

116
. "github.com/onsi/ginkgo/v2"
127
. "github.com/onsi/gomega"
@@ -16,36 +11,3 @@ func TestVcenterManager(t *testing.T) {
1611
RegisterFailHandler(Fail)
1712
RunSpecs(t, "VcenterManager Suite")
1813
}
19-
20-
var (
21-
CertPath string
22-
cmd *exec.Cmd
23-
keyPath string
24-
)
25-
26-
var _ = BeforeSuite(func() {
27-
28-
if runtime.GOOS != "windows" {
29-
workingDir, err := os.Getwd()
30-
Expect(err).NotTo(HaveOccurred())
31-
CertPath = filepath.Join(workingDir, "..", "fixtures", "dummycert")
32-
keyPath = filepath.Join(workingDir, "..", "fixtures", "dummykey")
33-
34-
vcsimBinary := filepath.Join(os.Getenv("GOPATH"), "bin", "vcsim")
35-
36-
cmd = exec.Command(vcsimBinary, "-tlscert", CertPath, "-tlskey", keyPath)
37-
38-
err = cmd.Start()
39-
Expect(err).ToNot(HaveOccurred())
40-
41-
time.Sleep(3 * time.Second) // the vcsim server needs a moment to come up
42-
}
43-
44-
})
45-
46-
var _ = AfterSuite(func() {
47-
if runtime.GOOS != "windows" && cmd != nil {
48-
err := cmd.Process.Kill()
49-
Expect(err).ToNot(HaveOccurred())
50-
}
51-
})

stembuild/iaas_cli/iaas_clients/vcenter_manager/vcenter_manager_test.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package vcenter_manager_test
33
import (
44
"context"
55
"errors"
6-
"runtime"
76

87
. "github.com/onsi/ginkgo/v2"
98
. "github.com/onsi/gomega"
@@ -111,7 +110,6 @@ var _ = Describe("VcenterManager", func() {
111110
})
112111

113112
It("returns an error if the finder does", func() {
114-
115113
guestErr := errors.New("not today, junior")
116114
fakeOpsManager := &vcenter_managerfakes.FakeOpsManager{}
117115
fakeOpsManager.ProcessManagerReturns(nil, guestErr)
@@ -124,48 +122,4 @@ var _ = Describe("VcenterManager", func() {
124122

125123
})
126124
})
127-
128-
Context("running against vcsim server", func() {
129-
Context("CloneVM", func() {
130-
It("clones a vm", func() {
131-
if runtime.GOOS == "windows" {
132-
Skip("windows cannot run a vcsim server")
133-
}
134-
135-
inventoryPath := "/DC0/vm/DC0_H0_VM0"
136-
clonePath := "/DC0/vm/DC0_H0_VM0_NewClone"
137-
138-
factoryConfig := &vcenter_manager.FactoryConfig{
139-
VCenterServer: "https://user:[email protected]:8989/sdk",
140-
Username: "user",
141-
Password: "pass",
142-
ClientCreator: &vcenter_manager.ClientCreator{},
143-
FinderCreator: &vcenter_manager.GovmomiFinderCreator{},
144-
RootCACertPath: CertPath,
145-
}
146-
147-
managerFactory := &vcenter_manager.ManagerFactory{
148-
Config: *factoryConfig,
149-
}
150-
151-
ctx := context.TODO()
152-
153-
vCenterManager, err := managerFactory.VCenterManager(ctx)
154-
Expect(err).ToNot(HaveOccurred())
155-
156-
err = vCenterManager.Login(ctx)
157-
Expect(err).ToNot(HaveOccurred())
158-
159-
vmToClone, err := vCenterManager.FindVM(ctx, inventoryPath)
160-
Expect(err).ToNot(HaveOccurred())
161-
162-
err = vCenterManager.CloneVM(ctx, vmToClone, clonePath)
163-
Expect(err).ToNot(HaveOccurred())
164-
165-
_, err = vCenterManager.FindVM(ctx, clonePath)
166-
Expect(err).ToNot(HaveOccurred())
167-
168-
})
169-
})
170-
})
171125
})

0 commit comments

Comments
 (0)