mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 19:15:34 +00:00
b2c55e62c8
Go now includes the GOROOT bin directory in $PATH while running tests and generate, so it is no longer necessary to construct a path using runtime.GOROOT(). Fixes #6689 Signed-off-by: James Tucker <james@tailscale.com>
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package version_test
|
|
|
|
import (
|
|
"flag"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
|
|
"tailscale.com/version"
|
|
)
|
|
|
|
var (
|
|
findModuleInfo = version.ExportFindModuleInfo
|
|
cmdName = version.ExportCmdName
|
|
)
|
|
|
|
func TestFindModuleInfo(t *testing.T) {
|
|
dir := t.TempDir()
|
|
name := filepath.Join(dir, "tailscaled-version-test")
|
|
out, err := exec.Command("go", "build", "-o", name, "tailscale.com/cmd/tailscaled").CombinedOutput()
|
|
if err != nil {
|
|
t.Fatalf("failed to build tailscaled: %v\n%s", err, out)
|
|
}
|
|
modinfo, err := findModuleInfo(name)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
prefix := "path\ttailscale.com/cmd/tailscaled\nmod\ttailscale.com"
|
|
if !strings.HasPrefix(modinfo, prefix) {
|
|
t.Errorf("unexpected modinfo contents %q", modinfo)
|
|
}
|
|
}
|
|
|
|
func exe() string {
|
|
if runtime.GOOS == "windows" {
|
|
return ".exe"
|
|
}
|
|
return ""
|
|
}
|
|
|
|
var findModuleInfoName = flag.String("module-info-file", "", "if non-empty, test findModuleInfo against this filename")
|
|
|
|
func TestFindModuleInfoManual(t *testing.T) {
|
|
exe := *findModuleInfoName
|
|
if exe == "" {
|
|
t.Skip("skipping without --module-info-file filename")
|
|
}
|
|
cmd := cmdName(exe)
|
|
mod, err := findModuleInfo(exe)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Logf("Got %q from: %s", cmd, mod)
|
|
}
|