mirror of
https://github.com/portainer/portainer.git
synced 2025-08-04 05:15:25 +02:00
fix(roar): return empty slices instead of nil for easier API compatibility BE-12053 (#932)
This commit is contained in:
parent
60bc04bc33
commit
bba3751268
2 changed files with 40 additions and 1 deletions
|
@ -69,6 +69,45 @@ func TestEdgeGroupInspectHandler(t *testing.T) {
|
||||||
assert.ElementsMatch(t, []portainer.EndpointID{1, 2, 3}, responseGroup.Endpoints)
|
assert.ElementsMatch(t, []portainer.EndpointID{1, 2, 3}, responseGroup.Endpoints)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEmptyEdgeGroupInspectHandler(t *testing.T) {
|
||||||
|
_, store := datastore.MustNewTestStore(t, true, true)
|
||||||
|
|
||||||
|
handler := NewHandler(testhelpers.NewTestRequestBouncer())
|
||||||
|
handler.DataStore = store
|
||||||
|
|
||||||
|
err := store.EndpointGroup().Create(&portainer.EndpointGroup{
|
||||||
|
ID: 1,
|
||||||
|
Name: "Test Group",
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
err = store.EdgeGroup().Create(&portainer.EdgeGroup{
|
||||||
|
ID: 1,
|
||||||
|
Name: "Test Edge Group",
|
||||||
|
EndpointIDs: roar.Roar[portainer.EndpointID]{},
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
rr := httptest.NewRecorder()
|
||||||
|
|
||||||
|
req := httptest.NewRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
"/edge_groups/1",
|
||||||
|
nil,
|
||||||
|
)
|
||||||
|
|
||||||
|
handler.ServeHTTP(rr, req)
|
||||||
|
require.Equal(t, http.StatusOK, rr.Result().StatusCode)
|
||||||
|
|
||||||
|
var responseGroup portainer.EdgeGroup
|
||||||
|
err = json.NewDecoder(rr.Body).Decode(&responseGroup)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
// Make sure the frontend does not get a null value but a [] instead
|
||||||
|
require.NotNil(t, responseGroup.Endpoints)
|
||||||
|
require.Len(t, responseGroup.Endpoints, 0)
|
||||||
|
}
|
||||||
|
|
||||||
func TestDynamicEdgeGroupInspectHandler(t *testing.T) {
|
func TestDynamicEdgeGroupInspectHandler(t *testing.T) {
|
||||||
_, store := datastore.MustNewTestStore(t, true, true)
|
_, store := datastore.MustNewTestStore(t, true, true)
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ func (r *Roar[T]) Intersection(other Roar[T]) {
|
||||||
// ToSlice converts the bitmap to a slice of elements
|
// ToSlice converts the bitmap to a slice of elements
|
||||||
func (r *Roar[T]) ToSlice() []T {
|
func (r *Roar[T]) ToSlice() []T {
|
||||||
if r.rb == nil {
|
if r.rb == nil {
|
||||||
return nil
|
return make([]T, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
slice := make([]T, 0, r.rb.GetCardinality())
|
slice := make([]T, 0, r.rb.GetCardinality())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue