Skip to content

Commit 68867ee

Browse files
committed
Add a simple unit test for available_rollbacks in checkin body
1 parent 5eeb78b commit 68867ee

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

internal/pkg/api/handleCheckin_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,25 @@ func TestValidateCheckinRequest(t *testing.T) {
11491149
},
11501150
},
11511151
expValid: validatedCheckin{
1152-
rawMeta: []byte(`{"elastic": {"agent": {"id": "testid", "fips": true}}}`),
1152+
rawMeta: []byte(`{"elastic": {"agent": {"id": "testid", "fips": true}}}`),
1153+
rawAvailableRollbacks: []byte(`[]`),
1154+
},
1155+
},
1156+
{
1157+
name: "Available rollbacks are correctly parsed",
1158+
req: &http.Request{
1159+
Body: io.NopCloser(strings.NewReader(`{"validJson": "test", "status": "test", "message": "test message", "available_rollbacks": [{"version": "1.2.3-SNAPSHOT", "valid_until": "2025-11-27T15:12:44Z"}]}`)),
1160+
},
1161+
cfg: &config.Server{
1162+
Limits: config.ServerLimits{
1163+
CheckinLimit: config.Limit{
1164+
MaxBody: 0,
1165+
},
1166+
},
1167+
},
1168+
expErr: nil,
1169+
expValid: validatedCheckin{
1170+
rawAvailableRollbacks: []byte(`[{"version": "1.2.3-SNAPSHOT", "valid_until": "2025-11-27T15:12:44Z"}]`),
11531171
},
11541172
},
11551173
}
@@ -1164,6 +1182,7 @@ func TestValidateCheckinRequest(t *testing.T) {
11641182
if tc.expErr == nil {
11651183
assert.NoError(t, err)
11661184
assert.Equal(t, tc.expValid.rawMeta, valid.rawMeta)
1185+
assert.JSONEq(t, string(tc.expValid.rawAvailableRollbacks), string(valid.rawAvailableRollbacks))
11671186
} else {
11681187
// Asserting error messages prior to ErrorAs becuase ErrorAs modifies
11691188
// the target error. If we assert error messages after calling ErrorAs

0 commit comments

Comments
 (0)