version_tailscale_test.go 806 B

1234567891011121314151617181920212223242526272829303132333435
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. //go:build tailscale_go
  4. package tailscaleroot
  5. import (
  6. "os"
  7. "runtime/debug"
  8. "strings"
  9. "testing"
  10. )
  11. func TestToolchainMatches(t *testing.T) {
  12. bi, ok := debug.ReadBuildInfo()
  13. if !ok {
  14. t.Fatal("failed to read build info")
  15. }
  16. var tsRev string
  17. for _, s := range bi.Settings {
  18. if s.Key == "tailscale.toolchain.rev" {
  19. tsRev = s.Value
  20. break
  21. }
  22. }
  23. want := strings.TrimSpace(GoToolchainRev)
  24. if tsRev != want {
  25. if os.Getenv("TS_PERMIT_TOOLCHAIN_MISMATCH") == "1" {
  26. t.Logf("tailscale.toolchain.rev = %q, want %q; but ignoring due to TS_PERMIT_TOOLCHAIN_MISMATCH=1", tsRev, want)
  27. return
  28. }
  29. t.Errorf("tailscale.toolchain.rev = %q, want %q; permit with TS_PERMIT_TOOLCHAIN_MISMATCH=1", tsRev, want)
  30. }
  31. }