Skip to content

Commit 8d5f8e5

Browse files
authored
Merge pull request #1597 from dougm/vcsim-run
vcsim: rename Example to Run
2 parents 1f7df82 + f962095 commit 8d5f8e5

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

event/example_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
func ExampleManager_Events() {
31-
simulator.Example(func(ctx context.Context, c *vim25.Client) error {
31+
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
3232
m := event.NewManager(c)
3333

3434
vm, err := find.NewFinder(c).VirtualMachine(ctx, "DC0_H0_VM0")

object/example_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
)
3333

3434
func ExampleResourcePool_Owner() {
35-
simulator.Example(func(ctx context.Context, c *vim25.Client) error {
35+
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
3636
finder := find.NewFinder(c)
3737

3838
for _, name := range []string{"DC0_H0_VM0", "DC0_C0_RP0_VM0"} {
@@ -62,7 +62,7 @@ func ExampleResourcePool_Owner() {
6262
}
6363

6464
func ExampleVirtualMachine_HostSystem() {
65-
simulator.Example(func(ctx context.Context, c *vim25.Client) error {
65+
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
6666
vm, err := find.NewFinder(c).VirtualMachine(ctx, "DC0_H0_VM0")
6767
if err != nil {
6868
return err
@@ -86,7 +86,7 @@ func ExampleVirtualMachine_HostSystem() {
8686
}
8787

8888
func ExampleVirtualMachine_Clone() {
89-
simulator.Example(func(ctx context.Context, c *vim25.Client) error {
89+
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
9090
finder := find.NewFinder(c)
9191
dc, err := finder.Datacenter(ctx, "DC0")
9292
if err != nil {
@@ -133,7 +133,7 @@ func ExampleVirtualMachine_Clone() {
133133
}
134134

135135
func ExampleVirtualMachine_Reconfigure() {
136-
simulator.Example(func(ctx context.Context, c *vim25.Client) error {
136+
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
137137
vm, err := find.NewFinder(c).VirtualMachine(ctx, "DC0_H0_VM0")
138138
if err != nil {
139139
return err
@@ -168,7 +168,7 @@ func ExampleCommon_Destroy() {
168168
model := simulator.VPX()
169169
model.Datastore = 2
170170

171-
simulator.Example(func(ctx context.Context, c *vim25.Client) error {
171+
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
172172
// Change to "LocalDS_0" will cause ResourceInUse error,
173173
// as simulator VMs created by the VPX model use "LocalDS_0".
174174
ds, err := find.NewFinder(c).Datastore(ctx, "LocalDS_1")
@@ -192,7 +192,7 @@ func ExampleCommon_Destroy() {
192192
}
193193

194194
func ExampleCustomFieldsManager_Set() {
195-
simulator.Example(func(ctx context.Context, c *vim25.Client) error {
195+
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
196196
m, err := object.GetCustomFieldsManager(c)
197197
if err != nil {
198198
return err

performance/example_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
func ExampleManager_ToMetricSeries() {
31-
simulator.Example(func(ctx context.Context, c *vim25.Client) error {
31+
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
3232
// Get virtual machines references
3333
m := view.NewManager(c)
3434

property/example_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
// Example to retrieve properties from a single object
3131
func ExampleCollector_RetrieveOne() {
32-
simulator.Example(func(ctx context.Context, c *vim25.Client) error {
32+
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
3333
pc := property.DefaultCollector(c)
3434

3535
obj, err := find.NewFinder(c).VirtualMachine(ctx, "DC0_H0_VM0")

simulator/model.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,9 @@ func (m *Model) Run(f func(context.Context, *vim25.Client) error) error {
546546
return f(ctx, c.Client)
547547
}
548548

549-
// Example calls Model.Run for each model and will panic if f returns an error.
549+
// Run calls Model.Run for each model and will panic if f returns an error.
550550
// If no model is specified, the VPX Model is used by default.
551-
func Example(f func(context.Context, *vim25.Client) error, model ...*Model) {
551+
func Run(f func(context.Context, *vim25.Client) error, model ...*Model) {
552552
m := model
553553
if len(m) == 0 {
554554
m = []*Model{VPX()}
@@ -561,3 +561,11 @@ func Example(f func(context.Context, *vim25.Client) error, model ...*Model) {
561561
}
562562
}
563563
}
564+
565+
// Test calls Run and expects the caller propagate any errors, via testing.T for example.
566+
func Test(f func(context.Context, *vim25.Client), model ...*Model) {
567+
Run(func(ctx context.Context, c *vim25.Client) error {
568+
f(ctx, c)
569+
return nil
570+
}, model...)
571+
}

view/example_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func ExampleContainerView_Retrieve() {
3434
model := simulator.VPX()
3535
model.Datacenter = 2
3636

37-
simulator.Example(func(ctx context.Context, c *vim25.Client) error {
37+
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
3838
m := view.NewManager(c)
3939
kind := []string{"HostSystem"}
4040

@@ -68,7 +68,7 @@ func ExampleContainerView_Retrieve() {
6868

6969
// Create a view of all VMs in the inventory, printing VM names that end with "_VM1".
7070
func ExampleContainerView_RetrieveWithFilter() {
71-
simulator.Example(func(ctx context.Context, c *vim25.Client) error {
71+
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
7272
m := view.NewManager(c)
7373
kind := []string{"VirtualMachine"}
7474

0 commit comments

Comments
 (0)