Skip to content

Commit

Permalink
Merge pull request #3612 from prziborowski/issue-3610
Browse files Browse the repository at this point in the history
fix: Set DuplicateName Object to duplicate object
  • Loading branch information
prziborowski authored Nov 4, 2024
2 parents 82b4ad6 + f9d093b commit 455de3e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions simulator/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (f *Folder) CreateFolder(ctx *Context, c *types.CreateFolder) soap.HasFault
if obj := ctx.Map.FindByName(name, f.ChildEntity); obj != nil {
r.Fault_ = Fault("", &types.DuplicateName{
Name: name,
Object: f.Self,
Object: obj.Reference(),
})

return r
Expand Down Expand Up @@ -250,7 +250,7 @@ func (f *Folder) CreateStoragePod(ctx *Context, c *types.CreateStoragePod) soap.
if obj := ctx.Map.FindByName(c.Name, f.ChildEntity); obj != nil {
r.Fault_ = Fault("", &types.DuplicateName{
Name: c.Name,
Object: f.Self,
Object: obj.Reference(),
})

return r
Expand Down
31 changes: 29 additions & 2 deletions simulator/folder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"

"github.com/vmware/govmomi"
"github.com/vmware/govmomi/fault"
"github.com/vmware/govmomi/find"
"github.com/vmware/govmomi/object"
"github.com/vmware/govmomi/simulator/esx"
Expand Down Expand Up @@ -73,7 +74,7 @@ func TestFolderESX(t *testing.T) {

_, err = f.CreateDatacenter(ctx, "foo")
if err == nil {
t.Error("expected error")
t.Fatal("expected error")
}

finder := find.NewFinder(c.Client, false)
Expand Down Expand Up @@ -119,6 +120,20 @@ func TestFolderVC(t *testing.T) {
t.Error(err)
}

_, err = f.CreateFolder(ctx, "foo")
if err == nil {
t.Error("expected error")
}

var dup *types.DuplicateName
_, ok := fault.As(err, &dup)
if !ok {
t.Fatal("expected DuplicateName type")
}
if dup.Object != ff.Reference() {
t.Fatal("Duplicate object not matched")
}

dc, err := f.CreateDatacenter(ctx, "bar")
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -151,11 +166,23 @@ func TestFolderVC(t *testing.T) {
t.Error("expected error")
}

_, err = folders.DatastoreFolder.CreateStoragePod(ctx, "pod")
pod, err := folders.DatastoreFolder.CreateStoragePod(ctx, "pod")
if err != nil {
t.Error(err)
}

_, err = folders.DatastoreFolder.CreateStoragePod(ctx, "pod")
if err == nil {
t.Error("expected error")
}
_, ok = fault.As(err, &dup)
if !ok {
t.Fatal("expected DuplicateName type")
}
if dup.Object != pod.Reference() {
t.Fatal("Duplicate object not matched")
}

tests := []struct {
name string
state types.TaskInfoState
Expand Down

0 comments on commit 455de3e

Please sign in to comment.