tailscale/hostinfo/hostinfo_linux_test.go
Tom Proctor 5f22f72636
hostinfo,build_docker.sh,tailcfg: more reliably detect being in a container (#13826)
Our existing container-detection tricks did not work on Kubernetes,
where Docker is no longer used as a container runtime. Extends the
existing go build tags for containers to the other container packages
and uses that to reliably detect builds that were created by Tailscale
for use in a container. Unfortunately this doesn't necessarily improve
detection for users' custom builds, but that's a separate issue.

Updates #13825

Signed-off-by: Tom Proctor <tomhjp@users.noreply.github.com>
2024-10-15 19:38:11 +01:00

43 lines
938 B
Go

// Copyright (c) Tailscale Inc & AUTHORS
// SPDX-License-Identifier: BSD-3-Clause
//go:build linux && !android && !ts_package_container
package hostinfo
import (
"testing"
)
func TestQnap(t *testing.T) {
version_info := `commit 2910d3a594b068024ed01a64a0fe4168cb001a12
Date: 2022-05-30 16:08:45 +0800
================================================
* QTSFW_5.0.0
remotes/origin/QTSFW_5.0.0`
got := getQnapQtsVersion(version_info)
want := "5.0.0"
if got != want {
t.Errorf("got %q; want %q", got, want)
}
got = getQnapQtsVersion("")
want = ""
if got != want {
t.Errorf("got %q; want %q", got, want)
}
got = getQnapQtsVersion("just a bunch of junk")
want = ""
if got != want {
t.Errorf("got %q; want %q", got, want)
}
}
func TestInContainer(t *testing.T) {
if got := inContainer(); !got.EqualBool(false) {
t.Errorf("inContainer = %v; want false due to absence of ts_package_container build tag", got)
}
}