testenv.go 488 B

123456789101112131415161718192021
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Package testenv provides utility functions for tests. It does not depend on
  4. // the `testing` package to allow usage in non-test code.
  5. package testenv
  6. import (
  7. "flag"
  8. "tailscale.com/types/lazy"
  9. )
  10. var lazyInTest lazy.SyncValue[bool]
  11. // InTest reports whether the current binary is a test binary.
  12. func InTest() bool {
  13. return lazyInTest.Get(func() bool {
  14. return flag.Lookup("test.v") != nil
  15. })
  16. }