From 9f002692778340a08b95284477220780434d364e Mon Sep 17 00:00:00 2001 From: mgold1234 Date: Thu, 10 Feb 2022 12:57:15 +0200 Subject: [PATCH] This PR fixes #82 and check that vnic doesn't has same network --- client_nic_create_test.go | 23 ++++++++++++++++------- client_nic_test.go | 13 +++++++------ client_vnicprofile_test.go | 2 +- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/client_nic_create_test.go b/client_nic_create_test.go index bf2bad1..f5bb1ef 100644 --- a/client_nic_create_test.go +++ b/client_nic_create_test.go @@ -59,7 +59,7 @@ func TestDuplicateVMNICCreationWithSameName(t *testing.T) { assertNICCount(t, vm, 0) } -func TestDuplicateVMNICCreationWithSameNameAndDiffNetwork(t *testing.T) { +func TestDuplicateVMNICCreationWithSameNameAndDiffVNICProfile(t *testing.T) { t.Parallel() helper := getHelper(t) nicName := "test_duplicate_name" @@ -79,12 +79,21 @@ func TestDuplicateVMNICCreationWithSameNameAndDiffNetwork(t *testing.T) { ovirtclient.CreateNICParams()) assertNICCount(t, vm, 1) DiffVNICProfile, _ := assertCanFindDiffVNICProfile(helper, helper.GetVNICProfileID()) - assertCannotCreateNICWithSameNameDiffNetwork( - t, - vm, - nicName, - DiffVNICProfile, - ovirtclient.CreateNICParams()) + if DiffVNICProfile == "" { + assertCannotCreateNICWithSameName( + t, + helper, + vm, + nicName, + ovirtclient.CreateNICParams()) + } else { + assertCannotCreateNICWithVNICProfile( + t, + vm, + nicName, + DiffVNICProfile, + ovirtclient.CreateNICParams()) + } assertNICCount(t, vm, 1) assertCanRemoveNIC(t, nic1) assertNICCount(t, vm, 0) diff --git a/client_nic_test.go b/client_nic_test.go index c54f679..a6a062e 100644 --- a/client_nic_test.go +++ b/client_nic_test.go @@ -41,22 +41,23 @@ func assertCannotCreateNICWithSameName( name string, params ovirtclient.BuildableNICParameters, ) { - nic, _ := vm.CreateNIC(name, helper.GetVNICProfileID(), params) - if nic != nil { + + _, err := vm.CreateNIC(name, helper.GetVNICProfileID(), params) + if err == nil { t.Fatalf("create 2 NICs with same name %s", name) } } -func assertCannotCreateNICWithSameNameDiffNetwork( +func assertCannotCreateNICWithVNICProfile( t *testing.T, vm ovirtclient.VM, name string, diffVNICProfile string, params ovirtclient.BuildableNICParameters, ) { - nic, _ := vm.CreateNIC(name, diffVNICProfile, params) - if nic != nil { - t.Fatalf("create 2 NICs with same name %s", name) + _, err := vm.CreateNIC(name, diffVNICProfile, params) + if err == nil { + t.Fatalf("create 2 NICs with same name %s and different VNICProfile (%v)", name, err) } } diff --git a/client_vnicprofile_test.go b/client_vnicprofile_test.go index ac5a609..d9443e9 100644 --- a/client_vnicprofile_test.go +++ b/client_vnicprofile_test.go @@ -68,5 +68,5 @@ func assertCanFindDiffVNICProfile(helper ovirtclient.TestHelper, vnicProfileID s return vnicID, nil } } - return vnicProfileID, fmt.Errorf("failed to find different VNIC profile ID for testing, use the exiting one") + return "", fmt.Errorf("failed to find different VNIC profile ID for testing, use the exiting one") }