Skip to content

Commit eecc2da

Browse files
committed
fix: add code coverage
1 parent c0e549b commit eecc2da

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

integration-test/collections/console_mps_apis.postman_collection.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,6 +1621,7 @@
16211621
" pm.expect(jsonData.tags.length).to.be.equal(0);\r",
16221622
" pm.expect(jsonData.mpsInstance).to.be.equal(\"\");\r",
16231623
" pm.expect(jsonData.connectionStatus).to.be.equal(false);\r",
1624+
" pm.expect(jsonData.useTLS).to.be.equal(true);\r",
16241625
"})"
16251626
],
16261627
"type": "text/javascript",
@@ -1633,7 +1634,7 @@
16331634
"header": [],
16341635
"body": {
16351636
"mode": "raw",
1636-
"raw": "{\r\n \"guid\": \"143e4567-e89b-12d3-a456-426614174000\",\r\n \"friendlyName\": \"friendlyName\",\r\n \"hostname\": \"hostname\",\r\n \"tags\": [],\r\n \"mpsusername\": \"admin\",\r\n \"deviceInfo\": {\r\n \"fwVersion\": \"16.1.30\",\r\n \"fwBuild\": \"3400\",\r\n \"fwSku\": \"11\",\r\n \"discovered\": true,\r\n \"firstDiscovered\": \"2026-05-20T00:00:00Z\",\r\n \"currentMode\": \"Admin\",\r\n \"features\": \"SOL,IDER,KVM\",\r\n \"ipAddress\": \"10.0.0.12\",\r\n \"lastSynced\": \"2026-05-21T00:00:00Z\",\r\n \"tlsMode\": \"TLS 1.2\",\r\n \"upid\": {\r\n \"oemPlatformIdType\": \"Not Set (0)\",\r\n \"oemId\": \"\",\r\n \"csmeId\": \"4A45A39C5ED9462082510000\"\r\n },\r\n \"amtEnabledInBIOS\": true,\r\n \"meInterfaceVersion\": \"16.1.25.2124\",\r\n \"dhcpEnabled\": true,\r\n \"certHashes\": [\r\n \"a1b2c3\",\r\n \"d4e5f6\"\r\n ],\r\n \"lmsInstalled\": true,\r\n \"lmsVersion\": \"2410.5.0.0\",\r\n \"osName\": \"linux\",\r\n \"osVersion\": \"6.8.0-51-generic\",\r\n \"osDistro\": \"Ubuntu 24.04 LTS\",\r\n \"cpuModel\": \"Intel(R) Core(TM) Ultra 7 165H\",\r\n \"osIpAddress\": \"10.49.76.163\",\r\n \"ethernetAdapterCount\": 2,\r\n \"monitorConnected\": true,\r\n \"ieee8021xEnabled\": false\r\n }\r\n}",
1637+
"raw": "{\r\n \"guid\": \"143e4567-e89b-12d3-a456-426614174000\",\r\n \"friendlyName\": \"friendlyName\",\r\n \"hostname\": \"hostname\",\r\n \"tags\": [],\r\n \"mpsusername\": \"admin\",\r\n \"useTLS\": true,\r\n \"deviceInfo\": {\r\n \"fwVersion\": \"16.1.30\",\r\n \"fwBuild\": \"3400\",\r\n \"fwSku\": \"11\",\r\n \"discovered\": true,\r\n \"firstDiscovered\": \"2026-05-20T00:00:00Z\",\r\n \"currentMode\": \"Admin\",\r\n \"features\": \"SOL,IDER,KVM\",\r\n \"ipAddress\": \"10.0.0.12\",\r\n \"lastSynced\": \"2026-05-21T00:00:00Z\",\r\n \"tlsMode\": \"TLS 1.2\",\r\n \"upid\": {\r\n \"oemPlatformIdType\": \"Not Set (0)\",\r\n \"oemId\": \"\",\r\n \"csmeId\": \"4A45A39C5ED9462082510000\"\r\n },\r\n \"amtEnabledInBIOS\": true,\r\n \"meInterfaceVersion\": \"16.1.25.2124\",\r\n \"dhcpEnabled\": true,\r\n \"certHashes\": [\r\n \"a1b2c3\",\r\n \"d4e5f6\"\r\n ],\r\n \"lmsInstalled\": true,\r\n \"lmsVersion\": \"2410.5.0.0\",\r\n \"osName\": \"linux\",\r\n \"osVersion\": \"6.8.0-51-generic\",\r\n \"osDistro\": \"Ubuntu 24.04 LTS\",\r\n \"cpuModel\": \"Intel(R) Core(TM) Ultra 7 165H\",\r\n \"osIpAddress\": \"10.49.76.163\",\r\n \"ethernetAdapterCount\": 2,\r\n \"monitorConnected\": true,\r\n \"ieee8021xEnabled\": false\r\n }\r\n}",
16371638
"options": {
16381639
"raw": {
16391640
"language": "json"

internal/controller/httpapi/v1/devices.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (dr *deviceRoutes) getByID(c *gin.Context) {
191191
func (dr *deviceRoutes) insert(c *gin.Context) {
192192
var device dto.Device
193193
if err := c.ShouldBindBodyWithJSON(&device); err != nil {
194-
validationErr := ErrValidationDevices.Wrap("insert", "ShouldBindJSON", err)
194+
validationErr := ErrValidationDevices.Wrap("insert", "ShouldBindBodyWithJSON", err)
195195
ErrorResponse(c, validationErr)
196196

197197
return

internal/controller/httpapi/v1/devices_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,22 @@ func TestDevicesInsertHonorsExplicitUseTLSFalse(t *testing.T) {
469469
require.Equal(t, string(jsonBytes), w.Body.String())
470470
}
471471

472+
func TestDevicesInsertRejectsInvalidJSON(t *testing.T) {
473+
t.Parallel()
474+
475+
_, engine := devicesTest(t)
476+
477+
// Invalid JSON should fail during request binding.
478+
body := []byte(`{invalid json}`)
479+
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, "/api/v1/devices", bytes.NewBuffer(body))
480+
require.NoError(t, err)
481+
482+
w := httptest.NewRecorder()
483+
engine.ServeHTTP(w, req)
484+
485+
require.Equal(t, http.StatusBadRequest, w.Code)
486+
}
487+
472488
// encoding/json unmarshals case-insensitively; the merge must see the field as
473489
// provided regardless of the casing the client used.
474490
func TestDevicesUpdatePartialPatchMixedCaseKeys(t *testing.T) {

internal/controller/openapi/devices.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (f *FuegoAdapter) registerDeviceMutationRoutes() {
110110
fuego.Post(f.server, "/api/v1/devices", f.createDevice,
111111
fuego.OptionTags("Devices"),
112112
fuego.OptionSummary("Create Device"),
113-
fuego.OptionDescription("Create a new device"),
113+
fuego.OptionDescription("Create a new device. If useTLS is omitted, it defaults to true."),
114114
fuego.OptionDefaultStatusCode(http.StatusCreated),
115115
protectedRouteOptions(),
116116
)

0 commit comments

Comments
 (0)