Files
threshold/internal/cmd/legacy_alias_test.go
T
shadowdaoandClaude Sonnet 5.5 d07030a10b Make in-place upgrade from HashiCorp Boundary seamless
Linux packages: migrate /etc/boundary.d to /etc/threshold.d without
clobbering, reuse the boundary service user, carry over service
enablement with a boundary.service alias, provide a boundary command.
Docker: accept /boundary/config.hcl, boundary command, /boundary symlink.
CLI: deprecation notice when invoked as boundary (stderr only).
Dev mode: also create *.threshold.dev aliases.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-12 11:12:29 -07:00

50 lines
1.3 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1
package cmd
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestInvokedAsLegacyName(t *testing.T) {
t.Parallel()
tests := []struct {
argv0 string
want bool
}{
{"boundary", true},
{"/usr/bin/boundary", true},
{"./boundary", true},
{`C:\bin\boundary.exe`, true},
{"Boundary.EXE", true},
{"threshold", false},
{"/usr/bin/threshold", false},
{"boundary-worker", false},
{"", false},
}
for _, tt := range tests {
t.Run(tt.argv0, func(t *testing.T) {
assert.Equal(t, tt.want, invokedAsLegacyName(tt.argv0))
})
}
}
func TestLegacyNameNotice(t *testing.T) {
t.Parallel()
env := func(m map[string]string) func(string) string {
return func(k string) string { return m[k] }
}
n := LegacyNameNotice("/usr/bin/boundary", env(nil))
assert.True(t, strings.HasSuffix(n, "\n"))
assert.Equal(t, 1, strings.Count(n, "\n"), "notice must be a single line")
assert.Contains(t, n, "threshold")
assert.Empty(t, LegacyNameNotice("/usr/bin/threshold", env(nil)))
assert.Empty(t, LegacyNameNotice("boundary", env(map[string]string{"COMP_LINE": "boundary auth"})))
assert.Empty(t, LegacyNameNotice("boundary", env(map[string]string{envNoLegacyNameNotice: "1"})))
}