Files
tailscale/version/version_test.go
Brad Fitzpatrick bd2a2d53d3 all: use Go 1.26 things, run most gofix modernizers
I omitted a lot of the min/max modernizers because they didn't
result in more clear code.

Some of it's older "for x := range 123".

Also: errors.AsType, any, fmt.Appendf, etc.

Updates #18682

Change-Id: I83a451577f33877f962766a5b65ce86f7696471c
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2026-03-06 13:32:03 -08:00

52 lines
1.2 KiB
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
package version_test
import (
"bytes"
"os"
"testing"
ts "tailscale.com"
"tailscale.com/version"
)
func TestAlpineTag(t *testing.T) {
if tag := readAlpineTag(t, "../Dockerfile.base"); tag == "" {
t.Fatal(`"FROM alpine:" not found in Dockerfile.base`)
} else if tag != ts.AlpineDockerTag {
t.Errorf("alpine version mismatch: Dockerfile.base has %q; ALPINE.txt has %q", tag, ts.AlpineDockerTag)
}
if tag := readAlpineTag(t, "../Dockerfile"); tag == "" {
t.Fatal(`"FROM alpine:" not found in Dockerfile`)
} else if tag != ts.AlpineDockerTag {
t.Errorf("alpine version mismatch: Dockerfile has %q; ALPINE.txt has %q", tag, ts.AlpineDockerTag)
}
}
func readAlpineTag(t *testing.T, file string) string {
f, err := os.ReadFile(file)
if err != nil {
t.Fatal(err)
}
for line := range bytes.SplitSeq(f, []byte{'\n'}) {
line = bytes.TrimSpace(line)
_, suf, ok := bytes.Cut(line, []byte("FROM alpine:"))
if !ok {
continue
}
return string(suf)
}
return ""
}
func TestShortAllocs(t *testing.T) {
allocs := int(testing.AllocsPerRun(10000, func() {
_ = version.Short()
}))
if allocs > 0 {
t.Errorf("allocs = %v; want 0", allocs)
}
}