fleet/server/platform/logging/testutils/test_logger.go
Victor Lyuboslavsky 36ad83f611
Android Wi-Fi profile withheld until cert installed on device (#42877)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #42405

Demo video: https://www.youtube.com/watch?v=F3nfFvwdj-c

# 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`.

## 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

* **New Features**
* Android Wi‑Fi configuration profiles that reference client
certificates are withheld until the certificate is installed or reaches
a terminal state.
* Host OS settings now show the specific pending reason in the detail
column when Android profiles are waiting on certificate installation.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-07 16:26:09 -05:00

29 lines
836 B
Go

package testutils
import (
"log/slog"
"testing"
)
// TestLogger returns a *slog.Logger that routes output through t.Log.
// Logs are only printed when a test fails (or with -v), keeping passing test output clean.
// In parallel tests, logs stay grouped with their test instead of interleaving on stdout.
//
// Example usage:
//
// func TestSomething(t *testing.T) {
// logger := testutils.TestLogger(t)
// svc := mypackage.NewService(logger)
// // ... test svc; log output only appears if the test fails
// }
func TestLogger(t testing.TB) *slog.Logger {
return slog.New(slog.NewTextHandler(tLogWriter{t}, nil))
}
// tLogWriter adapts testing.TB to io.Writer so slog output is captured by t.Log
type tLogWriter struct{ t testing.TB }
func (w tLogWriter) Write(p []byte) (int, error) {
w.t.Log(string(p))
return len(p), nil
}