2
0

testcontrol.go 2.1 KB

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