dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/dtos/responses/corecommand_test.go (about) 1 // 2 // Copyright (C) 2021 IOTech Ltd 3 // 4 // SPDX-License-Identifier: Apache-2.0 5 6 package responses 7 8 import ( 9 "net/http" 10 "testing" 11 12 "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/common" 13 "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/dtos" 14 15 "github.com/stretchr/testify/assert" 16 ) 17 18 func TestNewDeviceCoreCommandResponse(t *testing.T) { 19 expectedRequestId := "123456" 20 expectedStatusCode := http.StatusOK 21 expectedMessage := "unit test message" 22 testParameters := []dtos.CoreCommandParameter{ 23 {ResourceName: "resource", ValueType: common.ValueTypeInt8}, 24 } 25 expectedDeviceCoreCommand := dtos.DeviceCoreCommand{ 26 DeviceName: "testDevice1", 27 ProfileName: "testProfile", 28 CoreCommands: []dtos.CoreCommand{ 29 {Name: "testCommand1", Get: true, Set: false, Path: "/device/name/testDevice1/command/testCommand1", Url: "http://127.0.0.1:48082", Parameters: testParameters}, 30 {Name: "testCommand2", Get: false, Set: true, Path: "/device/name/testDevice1/command/testCommand2", Url: "http://127.0.0.1:48082", Parameters: testParameters}, 31 }, 32 } 33 actual := NewDeviceCoreCommandResponse(expectedRequestId, expectedMessage, expectedStatusCode, expectedDeviceCoreCommand) 34 35 assert.Equal(t, expectedRequestId, actual.RequestId) 36 assert.Equal(t, expectedStatusCode, actual.StatusCode) 37 assert.Equal(t, expectedMessage, actual.Message) 38 assert.Equal(t, expectedDeviceCoreCommand, actual.DeviceCoreCommand) 39 } 40 41 func TestNewMultiDeviceCoreCommandsResponse(t *testing.T) { 42 expectedRequestId := "123456" 43 expectedStatusCode := http.StatusOK 44 expectedMessage := "unit test message" 45 testParameters := []dtos.CoreCommandParameter{ 46 {ResourceName: "resource", ValueType: common.ValueTypeInt8}, 47 } 48 expectedDeviceCoreCommands := []dtos.DeviceCoreCommand{ 49 dtos.DeviceCoreCommand{ 50 DeviceName: "testDevice1", 51 ProfileName: "testProfile", 52 CoreCommands: []dtos.CoreCommand{ 53 {Name: "testCommand1", Get: true, Set: false, Path: "/device/name/testDevice1/command/testCommand1", Url: "http://127.0.0.1:48082", Parameters: testParameters}, 54 {Name: "testCommand2", Get: false, Set: true, Path: "/device/name/testDevice1/command/testCommand2", Url: "http://127.0.0.1:48082", Parameters: testParameters}, 55 }, 56 }, 57 dtos.DeviceCoreCommand{ 58 DeviceName: "testDevice2", 59 ProfileName: "testProfile", 60 CoreCommands: []dtos.CoreCommand{ 61 {Name: "testCommand3", Get: true, Set: false, Path: "/device/name/testDevice1/command/testCommand1", Url: "http://127.0.0.1:48082", Parameters: testParameters}, 62 {Name: "testCommand4", Get: false, Set: true, Path: "/device/name/testDevice1/command/testCommand2", Url: "http://127.0.0.1:48082", Parameters: testParameters}, 63 }, 64 }, 65 } 66 expectedTotalCount := uint32(2) 67 actual := NewMultiDeviceCoreCommandsResponse(expectedRequestId, expectedMessage, expectedStatusCode, expectedTotalCount, expectedDeviceCoreCommands) 68 69 assert.Equal(t, expectedRequestId, actual.RequestId) 70 assert.Equal(t, expectedStatusCode, actual.StatusCode) 71 assert.Equal(t, expectedMessage, actual.Message) 72 assert.Equal(t, expectedTotalCount, actual.TotalCount) 73 assert.Equal(t, expectedDeviceCoreCommands, actual.DeviceCoreCommands) 74 }