feature/featuretags: add test that all ts_omit_foo tags are declared
Updates #12614 Change-Id: I49351fe0c463af0b8d940e8088d4748906a8aec3 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
642d1aaa60
commit
036b6a1262
@@ -0,0 +1,13 @@
|
|||||||
|
// Copyright (c) Tailscale Inc & contributors
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
// Code generated by gen.go; DO NOT EDIT.
|
||||||
|
|
||||||
|
//go:build ts_omit_completion_scripts
|
||||||
|
|
||||||
|
package buildfeatures
|
||||||
|
|
||||||
|
// HasCompletionScripts is whether the binary was built with support for modular feature "embed CLI shell completion scripts".
|
||||||
|
// Specifically, it's whether the binary was NOT built with the "ts_omit_completion_scripts" build tag.
|
||||||
|
// It's a const so it can be used for dead code elimination.
|
||||||
|
const HasCompletionScripts = false
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
// Copyright (c) Tailscale Inc & contributors
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
// Code generated by gen.go; DO NOT EDIT.
|
||||||
|
|
||||||
|
//go:build !ts_omit_completion_scripts
|
||||||
|
|
||||||
|
package buildfeatures
|
||||||
|
|
||||||
|
// HasCompletionScripts is whether the binary was built with support for modular feature "embed CLI shell completion scripts".
|
||||||
|
// Specifically, it's whether the binary was NOT built with the "ts_omit_completion_scripts" build tag.
|
||||||
|
// It's a const so it can be used for dead code elimination.
|
||||||
|
const HasCompletionScripts = true
|
||||||
@@ -139,7 +139,11 @@ var Features = map[FeatureTag]FeatureMeta{
|
|||||||
},
|
},
|
||||||
"completion": {Sym: "Completion", Desc: "CLI shell completion"},
|
"completion": {Sym: "Completion", Desc: "CLI shell completion"},
|
||||||
"conn25": {Sym: "Conn25", Desc: "Route traffic for configured domains through connector devices"},
|
"conn25": {Sym: "Conn25", Desc: "Route traffic for configured domains through connector devices"},
|
||||||
"cloud": {Sym: "Cloud", Desc: "detect cloud environment to learn instances IPs and DNS servers"},
|
"completion_scripts": {
|
||||||
|
Sym: "CompletionScripts", Desc: "embed CLI shell completion scripts",
|
||||||
|
Deps: []FeatureTag{"completion"},
|
||||||
|
},
|
||||||
|
"cloud": {Sym: "Cloud", Desc: "detect cloud environment to learn instances IPs and DNS servers"},
|
||||||
"dbus": {
|
"dbus": {
|
||||||
Sym: "DBus",
|
Sym: "DBus",
|
||||||
Desc: "Linux DBus support",
|
Desc: "Linux DBus support",
|
||||||
|
|||||||
@@ -5,7 +5,12 @@ package featuretags
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"maps"
|
"maps"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"tailscale.com/util/set"
|
"tailscale.com/util/set"
|
||||||
@@ -83,3 +88,38 @@ func TestRequiredBy(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify that all "ts_omit_foo" build tags are declared in featuretags.go
|
||||||
|
func TestAllOmitBuildTagsDeclared(t *testing.T) {
|
||||||
|
dir, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
root := filepath.Join(dir, "..", "..")
|
||||||
|
|
||||||
|
cmd := exec.Command("git", "grep", "ts_omit_")
|
||||||
|
cmd.Dir = root
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
if _, err := exec.LookPath("git"); err != nil {
|
||||||
|
t.Skipf("git not found in PATH; skipping test")
|
||||||
|
}
|
||||||
|
t.Fatalf("git grep failed: %v\nOutput:\n%s", err, out)
|
||||||
|
}
|
||||||
|
rx := regexp.MustCompile(`\bts_omit_[\w_]+\b`)
|
||||||
|
found := set.Set[string]{}
|
||||||
|
rx.ReplaceAllFunc(out, func(tag []byte) []byte {
|
||||||
|
tagStr := string(tag)
|
||||||
|
found.Add(tagStr)
|
||||||
|
return tag
|
||||||
|
})
|
||||||
|
for tag := range found {
|
||||||
|
if strings.EqualFold(tag, "ts_omit_foo") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ft := FeatureTag(strings.TrimPrefix(tag, "ts_omit_"))
|
||||||
|
if _, ok := Features[ft]; !ok {
|
||||||
|
t.Errorf("found undeclared ts_omit_* build tags: %v", tag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user