tailscale/tempfork/acme/sync_to_upstream_test.go
Brad Fitzpatrick 079973de82
Some checks are pending
checklocks / checklocks (push) Waiting to run
CodeQL / Analyze (go) (push) Waiting to run
Dockerfile build / deploy (push) Waiting to run
CI / race-root-integration (1/4) (push) Waiting to run
CI / race-root-integration (2/4) (push) Waiting to run
CI / race-root-integration (3/4) (push) Waiting to run
CI / race-root-integration (4/4) (push) Waiting to run
CI / test (-coverprofile=/tmp/coverage.out, amd64) (push) Waiting to run
CI / test (-race, amd64, 1/3) (push) Waiting to run
CI / test (-race, amd64, 2/3) (push) Waiting to run
CI / test (-race, amd64, 3/3) (push) Waiting to run
CI / test (386) (push) Waiting to run
CI / windows (push) Waiting to run
CI / privileged (push) Waiting to run
CI / vm (push) Waiting to run
CI / race-build (push) Waiting to run
CI / cross (386, linux) (push) Waiting to run
CI / cross (amd64, darwin) (push) Waiting to run
CI / cross (amd64, freebsd) (push) Waiting to run
CI / cross (amd64, openbsd) (push) Waiting to run
CI / cross (amd64, windows) (push) Waiting to run
CI / cross (arm, 5, linux) (push) Waiting to run
CI / cross (arm, 7, linux) (push) Waiting to run
CI / cross (arm64, darwin) (push) Waiting to run
CI / cross (arm64, linux) (push) Waiting to run
CI / cross (arm64, windows) (push) Waiting to run
CI / cross (loong64, linux) (push) Waiting to run
CI / ios (push) Waiting to run
CI / crossmin (amd64, illumos) (push) Waiting to run
CI / crossmin (amd64, plan9) (push) Waiting to run
CI / crossmin (amd64, solaris) (push) Waiting to run
CI / crossmin (ppc64, aix) (push) Waiting to run
CI / android (push) Waiting to run
CI / wasm (push) Waiting to run
CI / tailscale_go (push) Waiting to run
CI / fuzz (push) Waiting to run
CI / depaware (push) Waiting to run
CI / go_generate (push) Waiting to run
CI / go_mod_tidy (push) Waiting to run
CI / licenses (push) Waiting to run
CI / staticcheck (386, windows) (push) Waiting to run
CI / staticcheck (amd64, darwin) (push) Waiting to run
CI / staticcheck (amd64, linux) (push) Waiting to run
CI / staticcheck (amd64, windows) (push) Waiting to run
CI / notify_slack (push) Blocked by required conditions
CI / check_mergeability (push) Blocked by required conditions
tempfork/acme: fix TestSyncedToUpstream with Windows line endings
Updates #10238

Change-Id: Ic85811c267679a9f79377f376d77dee3a9d92ce7
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-01-27 22:15:08 +00:00

71 lines
2.1 KiB
Go

package acme
import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
_ "github.com/tailscale/golang-x-crypto/acme" // so it's on disk for the test
)
// Verify that the files tempfork/acme/*.go (other than this test file) match the
// files in "github.com/tailscale/golang-x-crypto/acme" which is where we develop
// our fork of golang.org/x/crypto/acme and merge with upstream, but then we vendor
// just its acme package into tailscale.com/tempfork/acme.
//
// Development workflow:
//
// - make a change in github.com/tailscale/golang-x-crypto/acme
// - merge it (ideally with golang.org/x/crypto/acme too)
// - rebase github.com/tailscale/golang-x-crypto/acme with upstream x/crypto/acme
// as needed
// - in the tailscale.com repo, run "go get github.com/tailscale/golang-x-crypto/acme@main"
// - run go test ./tempfork/acme to watch it fail; the failure includes
// a shell command you should run to copy the *.go files from tailscale/golang-x-crypto
// to tailscale.com.
// - watch tests pass. git add it all.
// - send PR to tailscale.com
func TestSyncedToUpstream(t *testing.T) {
const pkg = "github.com/tailscale/golang-x-crypto/acme"
out, err := exec.Command("go", "list", "-f", "{{.Dir}}", pkg).Output()
if err != nil {
t.Fatalf("failed to find %s's location o disk: %v", pkg, err)
}
xDir := strings.TrimSpace(string(out))
t.Logf("at %s", xDir)
scanDir := func(dir string) map[string]string {
m := map[string]string{} // filename => Go contents
ents, err := os.ReadDir(dir)
if err != nil {
t.Fatal(err)
}
for _, de := range ents {
name := de.Name()
if name == "sync_to_upstream_test.go" {
continue
}
if !strings.HasSuffix(name, ".go") {
continue
}
b, err := os.ReadFile(filepath.Join(dir, name))
if err != nil {
t.Fatal(err)
}
m[name] = strings.ReplaceAll(string(b), "\r", "")
}
return m
}
want := scanDir(xDir)
got := scanDir(".")
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("files differ (-want +got):\n%s", diff)
t.Errorf("to fix, run from module root:\n\ncp %s/*.go ./tempfork/acme && ./tool/go mod tidy\n", xDir)
}
}