From b33c337baa9e1c773f96a3a5a54db84b773d53c1 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 11 Aug 2022 09:24:07 -0700 Subject: [PATCH] tailcfg: actually bump capver to 37, add test I documented capver 37 in 4ee64681a but forgot to bump the actual constant. I've done this previously too, so add a test to prevent it from happening again. Change-Id: I6f7659db1243d30672121a384beb386d9f9f5b98 Signed-off-by: Brad Fitzpatrick --- tailcfg/tailcfg.go | 2 +- tailcfg/tailcfg_test.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tailcfg/tailcfg.go b/tailcfg/tailcfg.go index a3f401a4d..ede343979 100644 --- a/tailcfg/tailcfg.go +++ b/tailcfg/tailcfg.go @@ -72,7 +72,7 @@ // 34: 2022-08-02: client understands CapabilityFileSharingTarget // 36: 2022-08-02: added PeersChangedPatch.{Key,DiscoKey,Online,LastSeen,KeyExpiry,Capabilities} // 37: 2022-08-09: added Debug.{SetForceBackgroundSTUN,SetRandomizeClientPort}; Debug are sticky -const CurrentCapabilityVersion CapabilityVersion = 36 +const CurrentCapabilityVersion CapabilityVersion = 37 type StableID string diff --git a/tailcfg/tailcfg_test.go b/tailcfg/tailcfg_test.go index 6a900bcae..36256ec02 100644 --- a/tailcfg/tailcfg_test.go +++ b/tailcfg/tailcfg_test.go @@ -8,13 +8,17 @@ "encoding" "encoding/json" "net/netip" + "os" "reflect" + "regexp" + "strconv" "strings" "testing" "time" "tailscale.com/tstest" "tailscale.com/types/key" + "tailscale.com/util/must" "tailscale.com/version" ) @@ -651,3 +655,20 @@ func TestRegisterRequestNilClone(t *testing.T) { t.Errorf("got = %v; want nil", got) } } + +// Tests that CurrentCapabilityVersion is bumped when the comment block above it gets bumped. +// We've screwed this up several times. +func TestCurrentCapabilityVersion(t *testing.T) { + f := must.Get(os.ReadFile("tailcfg.go")) + matches := regexp.MustCompile(`(?m)^//\s+(\d+): \d\d\d\d-\d\d-\d\d: `).FindAllStringSubmatch(string(f), -1) + max := 0 + for _, m := range matches { + n := must.Get(strconv.Atoi(m[1])) + if n > max { + max = n + } + } + if CapabilityVersion(max) != CurrentCapabilityVersion { + t.Errorf("CurrentCapabilityVersion = %d; want %d", CurrentCapabilityVersion, max) + } +}