Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.3 KiB
Go
Raw Permalink Normal View History

// 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"})))
}