mirror of
https://github.com/tailscale/tailscale.git
synced 2026-04-21 21:42:19 +02:00
The kernel version parser used strings.Cut with "-" to handle versions like "5.4.0-76-generic", but Debian uses "+" in versions like "6.12.41+deb13-amd64". Use strings.IndexAny to find the first "-" or "+" and truncate there. Fixes TestKernelVersion on Debian systems. Fixes #19395 Change-Id: I70e5f95682d54baf908e51f9f4b51c130b00aaaa Co-Authored-By: Brad Fitzpatrick <bradfitz@tailscale.com> Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
35 lines
869 B
Go
35 lines
869 B
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build linux
|
|
|
|
package tstest
|
|
|
|
import "testing"
|
|
|
|
func TestParseKernelVersion(t *testing.T) {
|
|
tests := []struct {
|
|
release string
|
|
major, minor, patch int
|
|
}{
|
|
{"5.15.0-76-generic", 5, 15, 0},
|
|
{"6.12.73+deb13-amd64", 6, 12, 73},
|
|
{"6.1.0-18-amd64", 6, 1, 0},
|
|
{"5.4.0", 5, 4, 0},
|
|
{"6.8.12", 6, 8, 12},
|
|
{"4.19.0+1", 4, 19, 0},
|
|
{"6.12.41+deb13-amd64", 6, 12, 41},
|
|
{"", 0, 0, 0},
|
|
{"not-a-version", 0, 0, 0},
|
|
{"1.2", 0, 0, 0},
|
|
{"a.b.c", 0, 0, 0},
|
|
}
|
|
for _, tt := range tests {
|
|
major, minor, patch := parseKernelVersion(tt.release)
|
|
if major != tt.major || minor != tt.minor || patch != tt.patch {
|
|
t.Errorf("parseKernelVersion(%q) = (%d, %d, %d), want (%d, %d, %d)",
|
|
tt.release, major, minor, patch, tt.major, tt.minor, tt.patch)
|
|
}
|
|
}
|
|
}
|