From c5812eea68afdb0e4e774f4f15ec4a34f0c3100c Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Tue, 13 Aug 2024 08:21:28 +0200 Subject: [PATCH] core: list return empty array instead of null, when no cores are installed (#2691) --- internal/cli/core/list.go | 6 +++--- internal/integrationtest/core/core_test.go | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/cli/core/list.go b/internal/cli/core/list.go index 24bae8a82ab..4fe1661b0e5 100644 --- a/internal/cli/core/list.go +++ b/internal/cli/core/list.go @@ -88,9 +88,9 @@ func GetList(ctx context.Context, srv rpc.ArduinoCoreServiceServer, inst *rpc.In } func newCoreListResult(in []*rpc.PlatformSummary, updatableOnly bool) *coreListResult { - res := &coreListResult{updatableOnly: updatableOnly} - for _, platformSummary := range in { - res.Platforms = append(res.Platforms, result.NewPlatformSummary(platformSummary)) + res := &coreListResult{updatableOnly: updatableOnly, Platforms: make([]*result.PlatformSummary, len(in))} + for i, platformSummary := range in { + res.Platforms[i] = result.NewPlatformSummary(platformSummary) } return res } diff --git a/internal/integrationtest/core/core_test.go b/internal/integrationtest/core/core_test.go index 1f8850f0856..08ed34fadfd 100644 --- a/internal/integrationtest/core/core_test.go +++ b/internal/integrationtest/core/core_test.go @@ -1174,6 +1174,7 @@ func TestCoreListWhenNoPlatformAreInstalled(t *testing.T) { stdout, _, err := cli.Run("core", "list", "--json") require.NoError(t, err) requirejson.Query(t, stdout, `.platforms | length`, `0`) + requirejson.Query(t, stdout, `.platforms | select(.!=null)`, `[]`) stdout, _, err = cli.Run("core", "list") require.NoError(t, err)