testcontrol.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright (c) Tailscale Inc & contributors
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Program testcontrol runs a simple test control server.
  4. package main
  5. import (
  6. "flag"
  7. "log"
  8. "net/http"
  9. "testing"
  10. "tailscale.com/tstest/integration"
  11. "tailscale.com/tstest/integration/testcontrol"
  12. "tailscale.com/types/logger"
  13. )
  14. var (
  15. flagNFake = flag.Int("nfake", 0, "number of fake nodes to add to network")
  16. )
  17. func main() {
  18. flag.Parse()
  19. var t fakeTB
  20. derpMap := integration.RunDERPAndSTUN(t, logger.Discard, "127.0.0.1")
  21. control := &testcontrol.Server{
  22. DERPMap: derpMap,
  23. ExplicitBaseURL: "http://127.0.0.1:9911",
  24. }
  25. for range *flagNFake {
  26. control.AddFakeNode()
  27. }
  28. mux := http.NewServeMux()
  29. mux.Handle("/", control)
  30. addr := "127.0.0.1:9911"
  31. log.Printf("listening on %s", addr)
  32. err := http.ListenAndServe(addr, mux)
  33. log.Fatal(err)
  34. }
  35. type fakeTB struct {
  36. *testing.T
  37. }
  38. func (t fakeTB) Cleanup(_ func()) {}
  39. func (t fakeTB) Error(args ...any) {
  40. t.Fatal(args...)
  41. }
  42. func (t fakeTB) Errorf(format string, args ...any) {
  43. t.Fatalf(format, args...)
  44. }
  45. func (t fakeTB) Fail() {
  46. t.Fatal("failed")
  47. }
  48. func (t fakeTB) FailNow() {
  49. t.Fatal("failed")
  50. }
  51. func (t fakeTB) Failed() bool {
  52. return false
  53. }
  54. func (t fakeTB) Fatal(args ...any) {
  55. log.Fatal(args...)
  56. }
  57. func (t fakeTB) Fatalf(format string, args ...any) {
  58. log.Fatalf(format, args...)
  59. }
  60. func (t fakeTB) Helper() {}
  61. func (t fakeTB) Log(args ...any) {
  62. log.Print(args...)
  63. }
  64. func (t fakeTB) Logf(format string, args ...any) {
  65. log.Printf(format, args...)
  66. }
  67. func (t fakeTB) Name() string {
  68. return "faketest"
  69. }
  70. func (t fakeTB) Setenv(key string, value string) {
  71. panic("not implemented")
  72. }
  73. func (t fakeTB) Skip(args ...any) {
  74. t.Fatal("skipped")
  75. }
  76. func (t fakeTB) SkipNow() {
  77. t.Fatal("skipnow")
  78. }
  79. func (t fakeTB) Skipf(format string, args ...any) {
  80. t.Logf(format, args...)
  81. t.Fatal("skipped")
  82. }
  83. func (t fakeTB) Skipped() bool {
  84. return false
  85. }
  86. func (t fakeTB) TempDir() string {
  87. panic("not implemented")
  88. }