From f9d093b9d77ab279116545f500b064e01a005ced Mon Sep 17 00:00:00 2001 From: Nathan Prziborowski Date: Mon, 4 Nov 2024 10:43:38 -0800 Subject: [PATCH] fix: Set DuplicateName Object to duplicate object Closes: #3610 Signed-off-by: Nathan Prziborowski --- simulator/folder.go | 4 ++-- simulator/folder_test.go | 31 +++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/simulator/folder.go b/simulator/folder.go index 4d6e96ec4..9eb19c7ee 100644 --- a/simulator/folder.go +++ b/simulator/folder.go @@ -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 @@ -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 diff --git a/simulator/folder_test.go b/simulator/folder_test.go index 0a8efa174..222ec822c 100644 --- a/simulator/folder_test.go +++ b/simulator/folder_test.go @@ -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" @@ -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) @@ -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) @@ -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