mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-22 11:01:54 +00:00
tstest/deptest: add test-only package to unify negative dep tests
Updates #8658 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
32d486e2bf
commit
7560435eb5
@@ -1,38 +1,24 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
// No need to run this on Windows where CI's slow enough. Then we don't need to
|
||||
// worry about "go.exe" etc.
|
||||
|
||||
//go:build !windows
|
||||
|
||||
package jsdeps
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"os/exec"
|
||||
"testing"
|
||||
|
||||
"tailscale.com/tstest/deptest"
|
||||
)
|
||||
|
||||
func TestDeps(t *testing.T) {
|
||||
cmd := exec.Command("go", "list", "-json", ".")
|
||||
cmd.Env = append(os.Environ(), "GOOS=js", "GOARCH=wasm")
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var res struct {
|
||||
Deps []string
|
||||
}
|
||||
if err := json.Unmarshal(out, &res); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, dep := range res.Deps {
|
||||
switch dep {
|
||||
case "runtime/pprof", "golang.org/x/net/http2/h2c", "net/http/pprof", "golang.org/x/net/proxy", "github.com/tailscale/goupnp":
|
||||
t.Errorf("package %q is not allowed as a dependency on JS", dep)
|
||||
}
|
||||
}
|
||||
t.Logf("got %d dependencies", len(res.Deps))
|
||||
deptest.DepChecker{
|
||||
GOOS: "js",
|
||||
GOARCH: "wasm",
|
||||
BadDeps: map[string]string{
|
||||
"runtime/pprof": "bloat",
|
||||
"golang.org/x/net/http2/h2c": "bloat",
|
||||
"net/http/pprof": "bloat",
|
||||
"golang.org/x/net/proxy": "bloat",
|
||||
"github.com/tailscale/goupnp": "bloat, which can't work anyway in wasm",
|
||||
},
|
||||
}.Check(t)
|
||||
}
|
||||
|
Reference in New Issue
Block a user