From b7daaf42bfbe8952e62852e5c5aef300f0be5ea2 Mon Sep 17 00:00:00 2001 From: Rick B Date: Fri, 18 Oct 2024 16:30:45 -0700 Subject: [PATCH] unit tests --- internal/entity/dto/v1/hardwareinfo.go | 2 +- internal/usecase/devices/info_test.go | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/entity/dto/v1/hardwareinfo.go b/internal/entity/dto/v1/hardwareinfo.go index a3211e64..785830db 100644 --- a/internal/entity/dto/v1/hardwareinfo.go +++ b/internal/entity/dto/v1/hardwareinfo.go @@ -5,7 +5,7 @@ type ( CIMComputerSystemPackage CIMComputerSystemPackage CIMSystemPackage CIMSystemPackage CIMChassis CIMChassis - CIMChip CIMChips + CIMChip CIMChips `json:"CIMChip" binding:"required"` CIMCard CIMCard CIMBIOSElement CIMBIOSElement CIMProcessor CIMProcessor diff --git a/internal/usecase/devices/info_test.go b/internal/usecase/devices/info_test.go index 47a7a156..94c4471e 100644 --- a/internal/usecase/devices/info_test.go +++ b/internal/usecase/devices/info_test.go @@ -16,6 +16,7 @@ import ( "github.com/open-amt-cloud-toolkit/console/internal/entity/dto/v1" "github.com/open-amt-cloud-toolkit/console/internal/mocks" devices "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices" + "github.com/open-amt-cloud-toolkit/console/internal/usecase/devices/wsman" "github.com/open-amt-cloud-toolkit/console/pkg/logger" ) @@ -271,14 +272,15 @@ func TestGetHardwareInfo(t *testing.T) { Return(man2) man2.EXPECT(). GetHardwareInfo(). - Return(gomock.Any(), nil) + Return(wsman.HWResults{}, nil) }, repoMock: func(repo *mocks.MockDeviceManagementRepository) { repo.EXPECT(). GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: gomock.Any(), + // res: dto.HardwareInfoResults{}, + res: dto.HardwareInfoResults{CIMComputerSystemPackage:dto.CIMComputerSystemPackage{Response:"", Responses:""}, CIMSystemPackage:dto.CIMSystemPackage{Responses:[]dto.CIMSystemPackagingResponses(nil)}, CIMChassis:dto.CIMChassis{Response:dto.CIMChassisResponse{Version:"", SerialNumber:"", Model:"", Manufacturer:"", ElementName:"", CreationClassName:"", Tag:"", OperationalStatus:[]int(nil), PackageType:0, ChassisPackageType:0}, Responses:[]interface {}(nil)}, CIMChip:dto.CIMChips{Responses:[]dto.CIMChipGet{dto.CIMChipGet{CanBeFRUed:false, CreationClassName:"", ElementName:"", Manufacturer:"", OperationalStatus:[]int(nil), Tag:"", Version:""}}}, CIMCard:dto.CIMCard{Response:dto.CIMCardResponseGet{CanBeFRUed:false, CreationClassName:"", ElementName:"", Manufacturer:"", Model:"", OperationalStatus:[]int(nil), PackageType:0, SerialNumber:"", Tag:"", Version:""}, Responses:[]interface {}(nil)}, CIMBIOSElement:dto.CIMBIOSElement{Response:dto.CIMBIOSElementResponse{TargetOperatingSystem:0, SoftwareElementID:"", SoftwareElementState:0, Name:"", OperationalStatus:[]int(nil), ElementName:"", Version:"", Manufacturer:"", PrimaryBIOS:false, ReleaseDate:dto.Time{DateTime:""}}, Responses:[]interface {}(nil)}, CIMProcessor:dto.CIMProcessor{Responses:[]dto.CIMProcessorResponse{dto.CIMProcessorResponse{DeviceID:"", CreationClassName:"", SystemName:"", SystemCreationClassName:"", ElementName:"", OperationalStatus:[]int(nil), HealthState:0, EnabledState:0, RequestedState:0, Role:"", Family:0, OtherFamilyDescription:"", UpgradeMethod:0, MaxClockSpeed:0, CurrentClockSpeed:0, Stepping:"", CPUStatus:0, ExternalBusClockSpeed:0}}}, CIMPhysicalPackage:dto.CIMPhysicalPackage{Responses:[]dto.CIMPhysicalPackageResponses(nil)}, CIMPhysicalMemory:dto.CIMPhysicalMemory{Responses:[]dto.CIMPhysicalMemoryResponse(nil)}, CIMMediaAccessDevice:dto.CIMMediaAccessDevice{Pull:[]interface {}(nil), Get:struct { Capabilities []int; CreationClassName string; DeviceID string; ElementName string; EnabledDefault int; EnabledState int; MaxMediaSize int; OperationalStatus []int; RequestedState int; Security int; SystemCreationClassName string; SystemName string }{Capabilities:[]int(nil), CreationClassName:"", DeviceID:"", ElementName:"", EnabledDefault:0, EnabledState:0, MaxMediaSize:0, OperationalStatus:[]int(nil), RequestedState:0, Security:0, SystemCreationClassName:"", SystemName:""}}}, err: nil, }, { @@ -290,7 +292,7 @@ func TestGetHardwareInfo(t *testing.T) { GetByID(context.Background(), device.GUID, ""). Return(nil, ErrGeneral) }, - res: nil, + res: dto.HardwareInfoResults{}, err: devices.ErrGeneral, }, { @@ -302,14 +304,14 @@ func TestGetHardwareInfo(t *testing.T) { Return(man2) man2.EXPECT(). GetHardwareInfo(). - Return(nil, ErrGeneral) + Return(wsman.HWResults{}, ErrGeneral) }, repoMock: func(repo *mocks.MockDeviceManagementRepository) { repo.EXPECT(). GetByID(context.Background(), device.GUID, ""). Return(device, nil) }, - res: nil, + res: dto.HardwareInfoResults{}, err: ErrGeneral, }, }