dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts@v1.0.2/clients/http/intervalaction_test.go (about) 1 // 2 // Copyright (C) 2021 IOTech Ltd 3 // Copyright (C) 2023 Intel Corporation 4 // 5 // SPDX-License-Identifier: Apache-2.0 6 7 package http 8 9 import ( 10 "context" 11 "net/http" 12 "path" 13 "testing" 14 15 "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/common" 16 "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/dtos" 17 dtoCommon "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/dtos/common" 18 "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/dtos/requests" 19 "dev.azure.com/aidainnovazione0090/DeviceManager/_git/go-mod-core-contracts/dtos/responses" 20 21 "github.com/stretchr/testify/assert" 22 "github.com/stretchr/testify/require" 23 ) 24 25 func TestAddIntervalActions(t *testing.T) { 26 ts := newTestServer(http.MethodPost, common.ApiIntervalActionRoute, []dtoCommon.BaseWithIdResponse{}) 27 defer ts.Close() 28 dto := dtos.NewIntervalAction(TestIntervalActionName, TestIntervalName, dtos.NewRESTAddress(TestHost, TestPort, TestHTTPMethod)) 29 request := []requests.AddIntervalActionRequest{requests.NewAddIntervalActionRequest(dto)} 30 client := NewIntervalActionClient(ts.URL, NewNullAuthenticationInjector(), false) 31 32 res, err := client.Add(context.Background(), request) 33 34 require.NoError(t, err) 35 assert.IsType(t, []dtoCommon.BaseWithIdResponse{}, res) 36 } 37 38 func TestPatchIntervalActions(t *testing.T) { 39 ts := newTestServer(http.MethodPatch, common.ApiIntervalActionRoute, []dtoCommon.BaseResponse{}) 40 defer ts.Close() 41 dto := dtos.NewUpdateIntervalAction(TestIntervalActionName) 42 request := []requests.UpdateIntervalActionRequest{requests.NewUpdateIntervalActionRequest(dto)} 43 client := NewIntervalActionClient(ts.URL, NewNullAuthenticationInjector(), false) 44 45 res, err := client.Update(context.Background(), request) 46 47 require.NoError(t, err) 48 assert.IsType(t, []dtoCommon.BaseResponse{}, res) 49 } 50 51 func TestQueryAllIntervalActions(t *testing.T) { 52 ts := newTestServer(http.MethodGet, common.ApiAllIntervalActionRoute, responses.MultiIntervalActionsResponse{}) 53 defer ts.Close() 54 client := NewIntervalActionClient(ts.URL, NewNullAuthenticationInjector(), false) 55 56 res, err := client.AllIntervalActions(context.Background(), 0, 10) 57 58 require.NoError(t, err) 59 assert.IsType(t, responses.MultiIntervalActionsResponse{}, res) 60 } 61 62 func TestQueryIntervalActionByName(t *testing.T) { 63 path := path.Join(common.ApiIntervalActionRoute, common.Name, TestIntervalActionName) 64 ts := newTestServer(http.MethodGet, path, responses.DeviceResponse{}) 65 defer ts.Close() 66 client := NewIntervalActionClient(ts.URL, NewNullAuthenticationInjector(), false) 67 68 res, err := client.IntervalActionByName(context.Background(), TestIntervalActionName) 69 70 require.NoError(t, err) 71 assert.IsType(t, responses.IntervalActionResponse{}, res) 72 } 73 74 func TestDeleteIntervalActionByName(t *testing.T) { 75 path := path.Join(common.ApiIntervalActionRoute, common.Name, TestIntervalActionName) 76 ts := newTestServer(http.MethodDelete, path, dtoCommon.BaseResponse{}) 77 defer ts.Close() 78 client := NewIntervalActionClient(ts.URL, NewNullAuthenticationInjector(), false) 79 80 res, err := client.DeleteIntervalActionByName(context.Background(), TestIntervalActionName) 81 82 require.NoError(t, err) 83 assert.IsType(t, dtoCommon.BaseResponse{}, res) 84 }