mirror of
https://github.com/fleetdm/fleet
synced 2026-05-06 06:48:54 +00:00
Fixes #30473 Refactore Datastore.EnrollHost and Datastore.EnrollOrbit methods to use functional options. Doing this refactor before adding new options to those methods. This should make the code more maintainable and easier to understand. No functional changes here. Just refactoring. # Checklist for submitter - [x] Added/updated automated tests <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Streamlined host and Orbit enrollment methods to use a flexible options-based pattern instead of fixed parameter lists. * Updated related tests and service logic to use the new options approach, improving clarity and extensibility for enrollment operations. * **New Features** * Introduced configuration options for host and Orbit enrollment, allowing more explicit and customizable parameter setting during enrollment. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
29 lines
786 B
Go
29 lines
786 B
Go
package test
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"testing"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
"github.com/google/uuid"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func SetOrbitEnrollment(t *testing.T, h *fleet.Host, ds fleet.Datastore) string {
|
|
orbitKey := uuid.New().String()
|
|
_, err := ds.EnrollOrbit(context.Background(),
|
|
fleet.WithEnrollOrbitHostInfo(fleet.OrbitHostInfo{
|
|
HardwareUUID: *h.OsqueryHostID,
|
|
HardwareSerial: h.HardwareSerial,
|
|
}),
|
|
fleet.WithEnrollOrbitNodeKey(orbitKey),
|
|
fleet.WithEnrollOrbitTeamID(h.TeamID),
|
|
)
|
|
require.NoError(t, err)
|
|
err = ds.SetOrUpdateHostOrbitInfo(
|
|
context.Background(), h.ID, "1.22.0", sql.NullString{String: "42", Valid: true}, sql.NullBool{Bool: true, Valid: true},
|
|
)
|
|
require.NoError(t, err)
|
|
return orbitKey
|
|
}
|