fleet/server/test/enrollment.go
Victor Lyuboslavsky 85a98d83dd
Refactor EnrollOrbit/EnrollHost (#30872)
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 -->
2025-07-15 17:22:02 -03:00

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
}