httpm_test.go 914 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package httpm
  4. import (
  5. "os"
  6. "os/exec"
  7. "path/filepath"
  8. "strings"
  9. "testing"
  10. )
  11. func TestUsedConsistently(t *testing.T) {
  12. dir, err := os.Getwd()
  13. if err != nil {
  14. t.Fatal(err)
  15. }
  16. rootDir := filepath.Join(dir, "../..")
  17. // If we don't have a .git directory, we're not in a git checkout (e.g.
  18. // a downstream package); skip this test.
  19. if _, err := os.Stat(filepath.Join(rootDir, ".git")); err != nil {
  20. t.Skipf("skipping test since .git doesn't exist: %v", err)
  21. }
  22. cmd := exec.Command("git", "grep", "-l", "-F", "http.Method")
  23. cmd.Dir = rootDir
  24. matches, _ := cmd.Output()
  25. for _, fn := range strings.Split(strings.TrimSpace(string(matches)), "\n") {
  26. switch fn {
  27. case "util/httpm/httpm.go", "util/httpm/httpm_test.go":
  28. continue
  29. }
  30. t.Errorf("http.MethodFoo constant used in %s; use httpm.FOO instead", fn)
  31. }
  32. }