sync_to_upstream_test.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package acme
  2. import (
  3. "os"
  4. "os/exec"
  5. "path/filepath"
  6. "strings"
  7. "testing"
  8. "github.com/google/go-cmp/cmp"
  9. _ "github.com/tailscale/golang-x-crypto/acme" // so it's on disk for the test
  10. )
  11. // Verify that the files tempfork/acme/*.go (other than this test file) match the
  12. // files in "github.com/tailscale/golang-x-crypto/acme" which is where we develop
  13. // our fork of golang.org/x/crypto/acme and merge with upstream, but then we vendor
  14. // just its acme package into tailscale.com/tempfork/acme.
  15. //
  16. // Development workflow:
  17. //
  18. // - make a change in github.com/tailscale/golang-x-crypto/acme
  19. // - merge it (ideally with golang.org/x/crypto/acme too)
  20. // - rebase github.com/tailscale/golang-x-crypto/acme with upstream x/crypto/acme
  21. // as needed
  22. // - in the tailscale.com repo, run "go get github.com/tailscale/golang-x-crypto/acme@main"
  23. // - run go test ./tempfork/acme to watch it fail; the failure includes
  24. // a shell command you should run to copy the *.go files from tailscale/golang-x-crypto
  25. // to tailscale.com.
  26. // - watch tests pass. git add it all.
  27. // - send PR to tailscale.com
  28. func TestSyncedToUpstream(t *testing.T) {
  29. const pkg = "github.com/tailscale/golang-x-crypto/acme"
  30. out, err := exec.Command("go", "list", "-f", "{{.Dir}}", pkg).Output()
  31. if err != nil {
  32. t.Fatalf("failed to find %s's location o disk: %v", pkg, err)
  33. }
  34. xDir := strings.TrimSpace(string(out))
  35. t.Logf("at %s", xDir)
  36. scanDir := func(dir string) map[string]string {
  37. m := map[string]string{} // filename => Go contents
  38. ents, err := os.ReadDir(dir)
  39. if err != nil {
  40. t.Fatal(err)
  41. }
  42. for _, de := range ents {
  43. name := de.Name()
  44. if name == "sync_to_upstream_test.go" {
  45. continue
  46. }
  47. if !strings.HasSuffix(name, ".go") {
  48. continue
  49. }
  50. b, err := os.ReadFile(filepath.Join(dir, name))
  51. if err != nil {
  52. t.Fatal(err)
  53. }
  54. m[name] = strings.ReplaceAll(string(b), "\r", "")
  55. }
  56. return m
  57. }
  58. want := scanDir(xDir)
  59. got := scanDir(".")
  60. if diff := cmp.Diff(want, got); diff != "" {
  61. t.Errorf("files differ (-want +got):\n%s", diff)
  62. t.Errorf("to fix, run from module root:\n\ncp %s/*.go ./tempfork/acme && ./tool/go mod tidy\n", xDir)
  63. }
  64. }