Bug: spec/labels endpoint should include the id (#12135)

spec/labels endpoint should include the ID prop
This commit is contained in:
Juan Fernandez 2023-06-06 09:11:03 -04:00 committed by GitHub
parent 206c1e60df
commit 1eb8bb800e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 2 deletions

View file

@ -0,0 +1 @@
- GET /api/v1/fleet/spec/labels/{name} endpoint should include the label id

View file

@ -140,7 +140,7 @@ func (ds *Datastore) GetLabelSpecs(ctx context.Context) ([]*fleet.LabelSpec, err
func (ds *Datastore) GetLabelSpec(ctx context.Context, name string) (*fleet.LabelSpec, error) {
var specs []*fleet.LabelSpec
query := `
SELECT name, description, query, platform, label_type, label_membership_type
SELECT id, name, description, query, platform, label_type, label_membership_type
FROM labels
WHERE name = ?
`

View file

@ -11,6 +11,7 @@ import (
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/fleetdm/fleet/v4/server/ptr"
"github.com/fleetdm/fleet/v4/server/test"
"github.com/google/go-cmp/cmp"
"github.com/jmoiron/sqlx"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -708,7 +709,10 @@ func testLabelsGetSpec(t *testing.T, ds *Datastore) {
for _, s := range expectedSpecs {
spec, err := ds.GetLabelSpec(context.Background(), s.Name)
require.Nil(t, err)
assert.Equal(t, s, spec)
require.True(t, cmp.Equal(s, spec, cmp.FilterPath(func(p cmp.Path) bool {
return p.String() == "ID"
}, cmp.Ignore())))
}
}

View file

@ -3185,6 +3185,7 @@ func (s *integrationTestSuite) TestLabelSpecs() {
var getResp getLabelSpecResponse
s.DoJSON("GET", fmt.Sprintf("/api/latest/fleet/spec/labels/%s", url.PathEscape(name)), nil, http.StatusOK, &getResp)
assert.Equal(t, name, getResp.Spec.Name)
assert.NotEqual(t, 0, getResp.Spec.ID)
// get a non-existing label spec
s.DoJSON("GET", "/api/latest/fleet/spec/labels/zzz", nil, http.StatusNotFound, &getResp)