Skip to content

Commit

Permalink
fix(6023): added test validating the new items matches the deprecated…
Browse files Browse the repository at this point in the history
… list
  • Loading branch information
kaanyalti committed Dec 27, 2024
1 parent 6fb2822 commit e15ab33
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/pkg/agent/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ func runContainerCmd(streams *cli.IOStreams, cfg setupConfig) error {
return err
}
}

if cfg.Fleet.Enroll {
var policy *kibanaPolicy
token := cfg.Fleet.EnrollmentToken
Expand Down
58 changes: 58 additions & 0 deletions testing/integration/validate_items_deprecated_list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package integration

import (
"encoding/json"
"io"
"net/http"
"testing"

"github.com/elastic/elastic-agent/pkg/testing/define"
"github.com/stretchr/testify/require"
)

type testKibanaApiKey struct {
ID string `json:"id"`
Name string `json:"name"`
Active bool `json:"active"`
PolicyID string `json:"policy_id"`
APIKey string `json:"api_key"`
}

type deprecatedBody struct {
List []testKibanaApiKey `json:"list"`
}

type newBody struct {
Items []testKibanaApiKey `json:"items"`
}

// TODO: Remove test after list deprecation is complete
func TestItemsMatchDeprecatedList(t *testing.T) {
info := define.Require(t, define.Requirements{
Group: Default,
Stack: &define.Stack{},
Local: true,
Sudo: false,
})

res, err := info.KibanaClient.Connection.Send(http.MethodGet, "/api/fleet/enrollment_api_keys", nil, nil, nil)
require.NoError(t, err)
defer res.Body.Close()

body, err := io.ReadAll(res.Body)
require.NoError(t, err)

dpb := deprecatedBody{}
nb := newBody{}

err = json.Unmarshal(body, &dpb)
require.NoError(t, err)

err = json.Unmarshal(body, &nb)
require.NoError(t, err)

require.Equal(t, len(dpb.List), len(nb.Items))
for i := 0; i < len(dpb.List); i++ {
require.Equal(t, dpb.List[i], nb.Items[i])
}
}

0 comments on commit e15ab33

Please sign in to comment.