Files
tailscale-custom/cmd/tailscale/cli/drive_macgui_test.go
T
Alex Chan 34267d5afa cmd/tailscale: print a helpful error for Taildrive CLI on macOS GUI
Rather than printing `unknown subcommand: drive` for any Taildrive
commands run in the macOS GUI, print an error message directing the user
to the GUI client and the docs page.

Updates #17210
Fixes #18823

Change-Id: I6435007b5911baee79274b56e3ee101e6bb6d809
Signed-off-by: Alex Chan <alexc@tailscale.com>
2026-03-23 09:27:27 +00:00

67 lines
1.6 KiB
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
//go:build !ts_omit_drive && ts_mac_gui
package cli
import (
"bytes"
"context"
"flag"
"strings"
"testing"
"github.com/peterbourgon/ff/v3/ffcli"
)
// In macOS GUI builds, the `drive` command should not appear in
// the help text generated by ffcli.
func TestDriveCommandHiddenInHelpText(t *testing.T) {
root := newRootCmd()
var buf bytes.Buffer
root.FlagSet = flag.NewFlagSet("tailscale", flag.ContinueOnError)
root.FlagSet.SetOutput(&buf)
ffcli.DefaultUsageFunc(root)
output := buf.String()
if strings.Contains(output, "drive") {
t.Errorf("found hidden command 'drive' in help output:\n%q", output)
}
}
// Running the drive command always prints an error pointing you to
// the GUI app, regardless of input.
func TestDriveCommandPrintsError(t *testing.T) {
commands := [][]string{
{"drive"},
{"drive", "share", "myfile.txt", "/path/to/myfile.txt"},
{"drive", "rename", "oldname.txt", "newname.txt"},
{"drive", "unshare", "myfile.txt"},
{"drive", "list"},
}
for _, args := range commands {
root := newRootCmd()
if err := root.Parse(args); err != nil {
t.Errorf("unable to parse args %q, got err %v", args, err)
continue
}
t.Logf("running `tailscale drive %q`", strings.Join(args, " "))
err := root.Run(context.Background())
if err == nil {
t.Error("expected error, but got nil", args)
}
expectedText := "Taildrive CLI commands are not supported when using the macOS GUI app."
if !strings.Contains(err.Error(), expectedText) {
t.Errorf("error was not expected: want %q, got %q", expectedText, err.Error())
}
}
}