tstest/deptest: add check that x/exp/{maps,slices} imported as xfoo

Updates #cleanup

Change-Id: I4cbb5e477c739deddf7a46b66f286c9fdb106279
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2023-10-03 19:12:37 -07:00 committed by Brad Fitzpatrick
parent 91b9899402
commit 93c6e1d53b
8 changed files with 44 additions and 7 deletions

View File

@ -186,7 +186,6 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa
golang.org/x/crypto/nacl/box from tailscale.com/types/key
golang.org/x/crypto/nacl/secretbox from golang.org/x/crypto/nacl/box
golang.org/x/crypto/salsa20/salsa from golang.org/x/crypto/nacl/box+
golang.org/x/exp/maps from tailscale.com/tailcfg
L golang.org/x/net/bpf from github.com/mdlayher/netlink+
golang.org/x/net/dns/dnsmessage from net+
golang.org/x/net/http/httpguts from net/http

View File

@ -8,11 +8,11 @@ package main
import (
"context"
"fmt"
"slices"
"strings"
"sync"
"go.uber.org/zap"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"

View File

@ -9,11 +9,11 @@ import (
"context"
"fmt"
"net/netip"
"slices"
"strings"
"sync"
"go.uber.org/zap"
"golang.org/x/exp/slices"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"

View File

@ -194,7 +194,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep
golang.org/x/crypto/pbkdf2 from software.sslmate.com/src/go-pkcs12
golang.org/x/crypto/salsa20/salsa from golang.org/x/crypto/nacl/box+
W golang.org/x/exp/constraints from github.com/dblohm7/wingoes/pe
golang.org/x/exp/maps from tailscale.com/cmd/tailscale/cli+
golang.org/x/exp/maps from tailscale.com/cmd/tailscale/cli
golang.org/x/net/bpf from github.com/mdlayher/netlink+
golang.org/x/net/dns/dnsmessage from net+
golang.org/x/net/http/httpguts from net/http+

View File

@ -19,12 +19,12 @@ import (
"log"
"os"
"os/exec"
"slices"
"sort"
"strings"
"time"
xmaps "golang.org/x/exp/maps"
"golang.org/x/exp/slices"
"tailscale.com/cmd/testwrapper/flakytest"
)

View File

@ -10,13 +10,13 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"net/netip"
"reflect"
"slices"
"strings"
"time"
"golang.org/x/exp/maps"
"tailscale.com/types/dnstype"
"tailscale.com/types/key"
"tailscale.com/types/opt"

View File

@ -10,7 +10,10 @@ import (
"encoding/json"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
"testing"
)
@ -52,5 +55,30 @@ func (c DepChecker) Check(t *testing.T) {
}
}
t.Logf("got %d dependencies", len(res.Deps))
}
// ImportAliasCheck checks that all packages are imported according to Tailscale
// conventions.
func ImportAliasCheck(t testing.TB, relDir string) {
dir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
dir = filepath.Join(dir, relDir)
cmd := exec.Command("git", "grep", "-n", "-F", `"golang.org/x/exp/`)
cmd.Dir = dir
matches, err := cmd.CombinedOutput()
if err != nil {
t.Logf("ignoring error: %v, %s", err, matches)
return
}
badRx := regexp.MustCompile(`^([^:]+:\d+):\s+"golang.org/x/exp/(slices|maps)"`)
if s := strings.TrimSpace(string(matches)); s != "" {
for _, line := range strings.Split(s, "\n") {
if m := badRx.FindStringSubmatch(line); m != nil {
t.Errorf("%s: the x/exp/%s package should be imported as x%s", m[1], m[2], m[2])
}
}
}
}

View File

@ -0,0 +1,10 @@
// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
package deptest
import "testing"
func TestImports(t *testing.T) {
ImportAliasCheck(t, "../../")
}