mirror of
https://github.com/fleetdm/fleet
synced 2026-05-06 14:58:33 +00:00
Fixes #31444 The changes are primarily in tests. The only changes in production code are a couple validations/checks for invalid values in: - mysql/apple_mdm.go - mysql/hosts.go - mysql/queries.go # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved handling of timestamp and default values across various features to prevent database errors and warnings. * Enhanced validation and data consistency for Apple Business Manager tokens and MDM profiles. * Updated test data and logic to comply with stricter database constraints and realistic scenarios, including date handling and field lengths. * **Chores** * Updated test setups to reflect schema changes, improve data integrity, and avoid future compatibility issues. * Standardized SQL mode and timestamp usage in test environments. * Refined test data for VPP apps, software installers, and device enrollments for better reliability. * **Tests** * Expanded and updated tests to cover new fields, stricter validation, and more accurate simulation of real-world conditions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
28 lines
993 B
Go
28 lines
993 B
Go
package test
|
|
|
|
import (
|
|
"reflect"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
// FunctionName returns the name of the function provided as the argument.
|
|
// Behavior is undefined if a non-function is passed.
|
|
func FunctionName(f interface{}) string {
|
|
fullName := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
|
|
elements := strings.Split(fullName, ".")
|
|
return elements[len(elements)-1]
|
|
}
|
|
|
|
// MakeTestChecksum creates a 16-byte checksum for testing purposes.
|
|
// It returns a byte slice with 15 zeros followed by the provided value as the last byte.
|
|
// This is commonly used in MDM profile tests to generate unique checksums.
|
|
func MakeTestChecksum(value byte) []byte {
|
|
return []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, value}
|
|
}
|
|
|
|
// MakeTestBytes creates a 16-byte array with sequential values from 1 to 16.
|
|
// This is commonly used in tests for checksums, tokens, and other 16-byte identifiers.
|
|
func MakeTestBytes() []byte {
|
|
return []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
|
}
|