fix(lint): make string repetitions constant

This commit is contained in:
Jan De Dobbeleer 2023-10-24 12:45:30 +02:00 committed by github-actions[bot]
parent 7b89595658
commit 46c6275630
4 changed files with 114 additions and 100 deletions

View file

@ -36,6 +36,20 @@ func TestBrewfatherSegment(t *testing.T) {
FakeReading3DateString := fmt.Sprintf("%d", FakeReading3Date.UnixMilli()) FakeReading3DateString := fmt.Sprintf("%d", FakeReading3Date.UnixMilli())
FakeBottlingDateString := fmt.Sprintf("%d", FakeBottlingDate.UnixMilli()) FakeBottlingDateString := fmt.Sprintf("%d", FakeBottlingDate.UnixMilli())
// TODO: make this smarter
beerRecipeText := `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":`
bottlingDate := `,"bottlingDate":`
batchText := `,"name":"Batch","measuredAbv": 1.3}`
batchNumberFermenting := `{"batchNo":18,"status":"Fermenting","brewDate":`
manualType := `,"type":"manual"}]`
jsonFiller := FakeBrewDateString + bottlingDate + FakeBottlingDateString + beerRecipeText + FakeFermStartDateString + batchText
batchReadingJSON := `[{"id":"manual","temp":19.5,"comment":"","sg":1.066,"time":`
batchReadingJSON2 := `,"type":"manual"}, {"id":"manual","temp":21,"comment":"","sg":1.063,"time":`
batchReadingJSON3 := `,"type":"manual"}, {"id":"manual","temp":15,"comment":"","sg":1.050,"time":`
cases := []struct { cases := []struct {
Case string Case string
BatchJSONResponse string BatchJSONResponse string
@ -48,90 +62,81 @@ func TestBrewfatherSegment(t *testing.T) {
Error error Error error
}{ }{
{ {
Case: "Planning Status", Case: "Planning Status",
BatchJSONResponse: ` BatchJSONResponse: `{"batchNo":18,"status":"Planning","brewDate":` + jsonFiller,
{"batchNo":18,"status":"Planning","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll
BatchReadingsJSONResponse: `[]`, BatchReadingsJSONResponse: `[]`,
Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
ExpectedString: " Fake Beer 1.3%", ExpectedString: " Fake Beer 1.3%",
ExpectedEnabled: true, ExpectedEnabled: true,
}, },
{ {
Case: "Brewing Status", Case: "Brewing Status",
BatchJSONResponse: ` BatchJSONResponse: `{"batchNo":18,"status":"Brewing","brewDate":` + jsonFiller,
{"batchNo":18,"status":"Brewing","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll
BatchReadingsJSONResponse: `[]`, BatchReadingsJSONResponse: `[]`,
Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
ExpectedString: " Fake Beer 1.3%", ExpectedString: " Fake Beer 1.3%",
ExpectedEnabled: true, ExpectedEnabled: true,
}, },
{ {
Case: "Fermenting Status, no readings", Case: "Fermenting Status, no readings",
BatchJSONResponse: ` BatchJSONResponse: batchNumberFermenting + jsonFiller,
{"batchNo":18,"status":"Fermenting","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll
BatchReadingsJSONResponse: `[]`, BatchReadingsJSONResponse: `[]`,
Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
ExpectedString: " 19d Fake Beer 1.3%", ExpectedString: " 19d Fake Beer 1.3%",
ExpectedEnabled: true, ExpectedEnabled: true,
}, },
{ {
Case: "Fermenting Status, one reading", Case: "Fermenting Status, one reading",
BatchJSONResponse: ` BatchJSONResponse: batchNumberFermenting + jsonFiller,
{"batchNo":18,"status":"Fermenting","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll BatchReadingsJSONResponse: batchReadingJSON + FakeReading1DateString + manualType,
BatchReadingsJSONResponse: `[{"id":"manual","temp":19.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + `,"type":"manual"}]`,
Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
ExpectedString: " 19d Fake Beer 1.3%: 1.066 19.5° →", ExpectedString: " 19d Fake Beer 1.3%: 1.066 19.5° →",
ExpectedEnabled: true, ExpectedEnabled: true,
}, },
{ {
Case: "Fermenting Status, two readings, temp trending up", Case: "Fermenting Status, two readings, temp trending up",
BatchJSONResponse: ` BatchJSONResponse: batchNumberFermenting + jsonFiller, //nolint:lll
{"batchNo":18,"status":"Fermenting","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll BatchReadingsJSONResponse: batchReadingJSON + FakeReading1DateString + batchReadingJSON2 + FakeReading2DateString + manualType, //nolint:lll
BatchReadingsJSONResponse: `[{"id":"manual","temp":19.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + `,"type":"manual"}, {"id":"manual","temp":21,"comment":"","sg":1.063,"time":` + FakeReading2DateString + `,"type":"manual"}]`, //nolint:lll
Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
ExpectedString: " 19d Fake Beer 1.3%: 1.063 21° ↗", ExpectedString: " 19d Fake Beer 1.3%: 1.063 21° ↗",
ExpectedEnabled: true, ExpectedEnabled: true,
}, },
{ {
Case: "Fermenting Status, three readings, temp trending hard down, include age of most recent reading", Case: "Fermenting Status, three readings, temp trending hard down, include age of most recent reading",
BatchJSONResponse: ` BatchJSONResponse: batchNumberFermenting + jsonFiller, //nolint:lll
{"batchNo":18,"status":"Fermenting","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll BatchReadingsJSONResponse: batchReadingJSON + FakeReading1DateString + batchReadingJSON2 + FakeReading2DateString + batchReadingJSON3 + FakeReading3DateString + manualType, //nolint:lll
BatchReadingsJSONResponse: `[{"id":"manual","temp":19.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + `,"type":"manual"}, {"id":"manual","temp":21,"comment":"","sg":1.063,"time":` + FakeReading2DateString + `,"type":"manual"}, {"id":"manual","temp":15,"comment":"","sg":1.050,"time":` + FakeReading3DateString + `,"type":"manual"}]`, //nolint:lll Template: "{{.StatusIcon}} {{.ReadingAge}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
Template: "{{.StatusIcon}} {{.ReadingAge}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
ExpectedString: " 451 19d Fake Beer 1.3%: 1.05 15° ↓↓", ExpectedString: " 451 19d Fake Beer 1.3%: 1.05 15° ↓↓",
ExpectedEnabled: true, ExpectedEnabled: true,
}, },
{ {
Case: "Bad batch json, readings fine", Case: "Bad batch json, readings fine",
BatchJSONResponse: ``, BatchJSONResponse: ``,
BatchReadingsJSONResponse: `[{"id":"manual","temp":19.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + `,"type":"manual"}, {"id":"manual","temp":21,"comment":"","sg":1.063,"time":` + FakeReading2DateString + `,"type":"manual"}, {"id":"manual","temp":15,"comment":"","sg":1.050,"time":` + FakeReading3DateString + `,"type":"manual"}]`, //nolint:lll BatchReadingsJSONResponse: batchReadingJSON + FakeReading1DateString + batchReadingJSON2 + FakeReading2DateString + batchReadingJSON3 + FakeReading3DateString + manualType, //nolint:lll
Template: "{{.StatusIcon}} {{.ReadingAge}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll Template: "{{.StatusIcon}} {{.ReadingAge}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
ExpectedString: "", ExpectedString: "",
ExpectedEnabled: false, ExpectedEnabled: false,
}, },
{ {
Case: "Conditioning Status", Case: "Conditioning Status",
BatchJSONResponse: ` BatchJSONResponse: `{"batchNo":18,"status":"Conditioning","brewDate":` + jsonFiller, //nolint:lll
{"batchNo":18,"status":"Conditioning","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll BatchReadingsJSONResponse: batchReadingJSON + FakeReading1DateString + batchReadingJSON2 + FakeReading2DateString + batchReadingJSON3 + FakeReading3DateString + manualType, //nolint:lll
BatchReadingsJSONResponse: `[{"id":"manual","temp":19.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + `,"type":"manual"}, {"id":"manual","temp":21,"comment":"","sg":1.063,"time":` + FakeReading2DateString + `,"type":"manual"}, {"id":"manual","temp":15,"comment":"","sg":1.050,"time":` + FakeReading3DateString + `,"type":"manual"}]`, //nolint:lll Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
Template: "{{.StatusIcon}} {{if .DaysBottledOrFermented}}{{.DaysBottledOrFermented}}d {{end}}{{.Recipe.Name}} {{.MeasuredAbv}}%{{ if and (.Reading) (eq .Status \"Fermenting\")}}: {{.Reading.Gravity}} {{.Reading.Temperature}}° {{.TemperatureTrendIcon}}{{end}}", //nolint:lll
ExpectedString: " 5d Fake Beer 1.3%", ExpectedString: " 5d Fake Beer 1.3%",
ExpectedEnabled: true, ExpectedEnabled: true,
}, },
{ {
Case: "Fermenting Status, test all unit conversions", Case: "Fermenting Status, test all unit conversions",
BatchJSONResponse: ` BatchJSONResponse: batchNumberFermenting + jsonFiller,
{"batchNo":18,"status":"Fermenting","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll BatchReadingsJSONResponse: `[{"id":"manual","temp":34.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + manualType,
BatchReadingsJSONResponse: `[{"id":"manual","temp":34.5,"comment":"","sg":1.066,"time":` + FakeReading1DateString + `,"type":"manual"}]`,
Template: "{{ if and (.Reading) (eq .Status \"Fermenting\") }}SG: ({{.Reading.Gravity}} Bx:{{.SGToBrix .Reading.Gravity}} P:{{.SGToPlato .Reading.Gravity}}), Temp: (C:{{.Reading.Temperature}} F:{{.DegCToF .Reading.Temperature}} K:{{.DegCToKelvin .Reading.Temperature}}){{end}}", //nolint:lll Template: "{{ if and (.Reading) (eq .Status \"Fermenting\") }}SG: ({{.Reading.Gravity}} Bx:{{.SGToBrix .Reading.Gravity}} P:{{.SGToPlato .Reading.Gravity}}), Temp: (C:{{.Reading.Temperature}} F:{{.DegCToF .Reading.Temperature}} K:{{.DegCToKelvin .Reading.Temperature}}){{end}}", //nolint:lll
ExpectedString: "SG: (1.066 Bx:16.13 P:16.13), Temp: (C:34.5 F:94.1 K:307.7)", ExpectedString: "SG: (1.066 Bx:16.13 P:16.13), Temp: (C:34.5 F:94.1 K:307.7)",
ExpectedEnabled: true, ExpectedEnabled: true,
}, },
{ {
Case: "Fermenting Status, test all unit conversions 2", Case: "Fermenting Status, test all unit conversions 2",
BatchJSONResponse: ` BatchJSONResponse: batchNumberFermenting + jsonFiller,
{"batchNo":18,"status":"Fermenting","brewDate":` + FakeBrewDateString + `,"bottlingDate":` + FakeBottlingDateString + `,"recipe":{"name":"Fake Beer"},"fermentationStartDate":` + FakeFermStartDateString + `,"name":"Batch","measuredAbv": 1.3}`, //nolint:lll BatchReadingsJSONResponse: `[{"id":"manual","temp":3.5,"comment":"","sg":1.004,"time":` + FakeReading1DateString + manualType,
BatchReadingsJSONResponse: `[{"id":"manual","temp":3.5,"comment":"","sg":1.004,"time":` + FakeReading1DateString + `,"type":"manual"}]`,
Template: "{{ if and (.Reading) (eq .Status \"Fermenting\") }}SG: ({{.Reading.Gravity}} Bx:{{.SGToBrix .Reading.Gravity}} P:{{.SGToPlato .Reading.Gravity}}), Temp: (C:{{.Reading.Temperature}} F:{{.DegCToF .Reading.Temperature}} K:{{.DegCToKelvin .Reading.Temperature}}){{end}}", //nolint:lll Template: "{{ if and (.Reading) (eq .Status \"Fermenting\") }}SG: ({{.Reading.Gravity}} Bx:{{.SGToBrix .Reading.Gravity}} P:{{.SGToPlato .Reading.Gravity}}), Temp: (C:{{.Reading.Temperature}} F:{{.DegCToF .Reading.Temperature}} K:{{.DegCToKelvin .Reading.Temperature}}){{end}}", //nolint:lll
ExpectedString: "SG: (1.004 Bx:1.03 P:1.03), Temp: (C:3.5 F:38.3 K:276.7)", ExpectedString: "SG: (1.004 Bx:1.03 P:1.03), Temp: (C:3.5 F:38.3 K:276.7)",
ExpectedEnabled: true, ExpectedEnabled: true,

View file

@ -18,7 +18,9 @@ import (
) )
const ( const (
branchName = "main" branchName = "main"
dotGit = "dev/.git"
dotGitSubmodule = "dev/.git/modules/submodule"
) )
func TestEnabledGitNotFound(t *testing.T) { func TestEnabledGitNotFound(t *testing.T) {
@ -88,23 +90,23 @@ func TestEnabledInWorktree(t *testing.T) {
WorkingFolderContent: TestRootPath + "dev/worktree.git\n", WorkingFolderContent: TestRootPath + "dev/worktree.git\n",
ExpectedWorkingFolder: TestRootPath + "dev/.git/worktrees/folder_worktree", ExpectedWorkingFolder: TestRootPath + "dev/.git/worktrees/folder_worktree",
ExpectedRealFolder: TestRootPath + "dev/worktree", ExpectedRealFolder: TestRootPath + "dev/worktree",
ExpectedRootFolder: TestRootPath + "dev/.git", ExpectedRootFolder: TestRootPath + dotGit,
}, },
{ {
Case: "submodule", Case: "submodule",
ExpectedEnabled: true, ExpectedEnabled: true,
WorkingFolder: "./.git/modules/submodule", WorkingFolder: "./.git/modules/submodule",
ExpectedWorkingFolder: TestRootPath + "dev/.git/modules/submodule", ExpectedWorkingFolder: TestRootPath + dotGitSubmodule,
ExpectedRealFolder: TestRootPath + "dev/.git/modules/submodule", ExpectedRealFolder: TestRootPath + dotGitSubmodule,
ExpectedRootFolder: TestRootPath + "dev/.git/modules/submodule", ExpectedRootFolder: TestRootPath + dotGitSubmodule,
}, },
{ {
Case: "submodule with root working folder", Case: "submodule with root working folder",
ExpectedEnabled: true, ExpectedEnabled: true,
WorkingFolder: TestRootPath + "repo/.git/modules/submodule", WorkingFolder: TestRootPath + dotGitSubmodule,
ExpectedWorkingFolder: TestRootPath + "repo/.git/modules/submodule", ExpectedWorkingFolder: TestRootPath + dotGitSubmodule,
ExpectedRealFolder: TestRootPath + "repo/.git/modules/submodule", ExpectedRealFolder: TestRootPath + dotGitSubmodule,
ExpectedRootFolder: TestRootPath + "repo/.git/modules/submodule", ExpectedRootFolder: TestRootPath + dotGitSubmodule,
}, },
{ {
Case: "submodule with worktrees", Case: "submodule with worktrees",
@ -126,12 +128,12 @@ func TestEnabledInWorktree(t *testing.T) {
}, },
} }
fileInfo := &platform.FileInfo{ fileInfo := &platform.FileInfo{
Path: TestRootPath + "dev/.git", Path: TestRootPath + dotGit,
ParentFolder: TestRootPath + "dev", ParentFolder: TestRootPath + "dev",
} }
for _, tc := range cases { for _, tc := range cases {
env := new(mock.MockedEnvironment) env := new(mock.MockedEnvironment)
env.On("FileContent", TestRootPath+"dev/.git").Return(fmt.Sprintf("gitdir: %s", tc.WorkingFolder)) env.On("FileContent", TestRootPath+dotGit).Return(fmt.Sprintf("gitdir: %s", tc.WorkingFolder))
env.On("FileContent", filepath.Join(tc.WorkingFolder, tc.WorkingFolderAddon)).Return(tc.WorkingFolderContent) env.On("FileContent", filepath.Join(tc.WorkingFolder, tc.WorkingFolderAddon)).Return(tc.WorkingFolderContent)
env.On("HasFilesInDir", tc.WorkingFolder, tc.WorkingFolderAddon).Return(true) env.On("HasFilesInDir", tc.WorkingFolder, tc.WorkingFolderAddon).Return(true)
env.On("HasFilesInDir", tc.WorkingFolder, "HEAD").Return(true) env.On("HasFilesInDir", tc.WorkingFolder, "HEAD").Return(true)

View file

@ -13,7 +13,10 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
const testKubectlAllInfoTemplate = "{{.Context}} :: {{.Namespace}} :: {{.User}} :: {{.Cluster}}" const (
testKubectlAllInfoTemplate = "{{.Context}} :: {{.Namespace}} :: {{.User}} :: {{.Cluster}}"
contextMarker = "currentcontextmarker"
)
func TestKubectlSegment(t *testing.T) { func TestKubectlSegment(t *testing.T) {
standardTemplate := "{{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}}" standardTemplate := "{{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}}"
@ -40,7 +43,7 @@ func TestKubectlSegment(t *testing.T) {
Case: "kubeconfig incomplete", Case: "kubeconfig incomplete",
Template: testKubectlAllInfoTemplate, Template: testKubectlAllInfoTemplate,
ParseKubeConfig: true, ParseKubeConfig: true,
Kubeconfig: "currentcontextmarker" + lsep + "contextdefinitionincomplete", Kubeconfig: contextMarker + lsep + "contextdefinitionincomplete",
Files: testKubeConfigFiles, Files: testKubeConfigFiles,
ExpectedString: "ctx :: :: ::", ExpectedString: "ctx :: :: ::",
ExpectedEnabled: true, ExpectedEnabled: true,
@ -101,7 +104,7 @@ func TestKubectlSegment(t *testing.T) {
Case: "kubeconfig multiple current marker first", Case: "kubeconfig multiple current marker first",
Template: testKubectlAllInfoTemplate, Template: testKubectlAllInfoTemplate,
ParseKubeConfig: true, ParseKubeConfig: true,
Kubeconfig: "" + lsep + "currentcontextmarker" + lsep + "contextdefinition" + lsep + "contextredefinition", Kubeconfig: "" + lsep + contextMarker + lsep + "contextdefinition" + lsep + "contextredefinition",
Files: testKubeConfigFiles, Files: testKubeConfigFiles,
ExpectedString: "ctx :: ns :: usr :: cl", ExpectedString: "ctx :: ns :: usr :: cl",
ExpectedEnabled: true, ExpectedEnabled: true,
@ -109,7 +112,7 @@ func TestKubectlSegment(t *testing.T) {
{ {
Case: "kubeconfig multiple context first", Case: "kubeconfig multiple context first",
Template: testKubectlAllInfoTemplate, ParseKubeConfig: true, Template: testKubectlAllInfoTemplate, ParseKubeConfig: true,
Kubeconfig: "contextdefinition" + lsep + "contextredefinition" + lsep + "currentcontextmarker" + lsep, Kubeconfig: "contextdefinition" + lsep + "contextredefinition" + lsep + contextMarker + lsep,
Files: testKubeConfigFiles, Files: testKubeConfigFiles,
ExpectedString: "ctx :: ns :: usr :: cl", ExpectedString: "ctx :: ns :: usr :: cl",
ExpectedEnabled: true, ExpectedEnabled: true,
@ -185,7 +188,7 @@ contexts:
namespace: ns namespace: ns
name: ctx name: ctx
`, `,
"currentcontextmarker": ` contextMarker: `
apiVersion: v1 apiVersion: v1
current-context: ctx current-context: ctx
`, `,

View file

@ -14,6 +14,15 @@ import (
mock2 "github.com/stretchr/testify/mock" mock2 "github.com/stretchr/testify/mock"
) )
const (
homeDir = "/home/someone"
homeDirWindows = "C:\\Users\\someone"
fooBarMan = "\\foo\\bar\\man"
abc = "/abc"
abcd = "/a/b/c/d"
cdefg = "/c/d/e/f/g"
)
func renderTemplateNoTrimSpace(env *mock.MockedEnvironment, segmentTemplate string, context any) string { func renderTemplateNoTrimSpace(env *mock.MockedEnvironment, segmentTemplate string, context any) string {
found := false found := false
for _, call := range env.Mock.ExpectedCalls { for _, call := range env.Mock.ExpectedCalls {
@ -46,11 +55,6 @@ func renderTemplate(env *mock.MockedEnvironment, segmentTemplate string, context
return strings.TrimSpace(renderTemplateNoTrimSpace(env, segmentTemplate, context)) return strings.TrimSpace(renderTemplateNoTrimSpace(env, segmentTemplate, context))
} }
const (
homeDir = "/home/someone"
homeDirWindows = "C:\\Users\\someone"
)
func TestParent(t *testing.T) { func TestParent(t *testing.T) {
cases := []struct { cases := []struct {
Case string Case string
@ -529,7 +533,7 @@ func TestAgnosterPathStyles(t *testing.T) {
Style: AgnosterShort, Style: AgnosterShort,
Expected: ".. > bar > man", Expected: ".. > bar > man",
HomePath: homeDirWindows, HomePath: homeDirWindows,
Pwd: homeDirWindows + "\\foo\\bar\\man", Pwd: homeDirWindows + fooBarMan,
GOOS: platform.WINDOWS, GOOS: platform.WINDOWS,
PathSeparator: "\\", PathSeparator: "\\",
FolderSeparatorIcon: " > ", FolderSeparatorIcon: " > ",
@ -677,7 +681,7 @@ func TestAgnosterPathStyles(t *testing.T) {
Style: AgnosterShort, Style: AgnosterShort,
Expected: "~ > .. > bar > man", Expected: "~ > .. > bar > man",
HomePath: homeDirWindows, HomePath: homeDirWindows,
Pwd: homeDirWindows + "\\foo\\bar\\man", Pwd: homeDirWindows + fooBarMan,
GOOS: platform.WINDOWS, GOOS: platform.WINDOWS,
PathSeparator: "\\", PathSeparator: "\\",
FolderSeparatorIcon: " > ", FolderSeparatorIcon: " > ",
@ -687,7 +691,7 @@ func TestAgnosterPathStyles(t *testing.T) {
Style: AgnosterShort, Style: AgnosterShort,
Expected: "~ > foo > bar > man", Expected: "~ > foo > bar > man",
HomePath: homeDirWindows, HomePath: homeDirWindows,
Pwd: homeDirWindows + "\\foo\\bar\\man", Pwd: homeDirWindows + fooBarMan,
GOOS: platform.WINDOWS, GOOS: platform.WINDOWS,
PathSeparator: "\\", PathSeparator: "\\",
FolderSeparatorIcon: " > ", FolderSeparatorIcon: " > ",
@ -774,26 +778,26 @@ func TestFullAndFolderPath(t *testing.T) {
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", Expected: "/"}, {Style: Full, FolderSeparatorIcon: "|", Pwd: "/", Expected: "/"},
{Style: Full, Pwd: "/", Expected: "/"}, {Style: Full, Pwd: "/", Expected: "/"},
{Style: Full, Pwd: homeDir, Expected: "~"}, {Style: Full, Pwd: homeDir, Expected: "~"},
{Style: Full, Pwd: homeDir + "/abc", Expected: "~/abc"}, {Style: Full, Pwd: homeDir + abc, Expected: "~/abc"},
{Style: Full, Pwd: homeDir + "/abc", Expected: homeDir + "/abc", DisableMappedLocations: true}, {Style: Full, Pwd: homeDir + abc, Expected: homeDir + abc, DisableMappedLocations: true},
{Style: Full, Pwd: "/a/b/c/d", Expected: "/a/b/c/d"}, {Style: Full, Pwd: abcd, Expected: abcd},
{Style: Full, FolderSeparatorIcon: "|", Pwd: homeDir, Expected: "~"}, {Style: Full, FolderSeparatorIcon: "|", Pwd: homeDir, Expected: "~"},
{Style: Full, FolderSeparatorIcon: "|", Pwd: homeDir, Expected: "/home|someone", DisableMappedLocations: true}, {Style: Full, FolderSeparatorIcon: "|", Pwd: homeDir, Expected: "/home|someone", DisableMappedLocations: true},
{Style: Full, FolderSeparatorIcon: "|", Pwd: homeDir + "/abc", Expected: "~|abc"}, {Style: Full, FolderSeparatorIcon: "|", Pwd: homeDir + abc, Expected: "~|abc"},
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/a/b/c/d", Expected: "/a|b|c|d"}, {Style: Full, FolderSeparatorIcon: "|", Pwd: abcd, Expected: "/a|b|c|d"},
{Style: Folder, Pwd: "/", Expected: "/"}, {Style: Folder, Pwd: "/", Expected: "/"},
{Style: Folder, Pwd: homeDir, Expected: "~"}, {Style: Folder, Pwd: homeDir, Expected: "~"},
{Style: Folder, Pwd: homeDir, Expected: "someone", DisableMappedLocations: true}, {Style: Folder, Pwd: homeDir, Expected: "someone", DisableMappedLocations: true},
{Style: Folder, Pwd: homeDir + "/abc", Expected: "abc"}, {Style: Folder, Pwd: homeDir + abc, Expected: "abc"},
{Style: Folder, Pwd: "/a/b/c/d", Expected: "d"}, {Style: Folder, Pwd: abcd, Expected: "d"},
{Style: Folder, FolderSeparatorIcon: "|", Pwd: "/", Expected: "/"}, {Style: Folder, FolderSeparatorIcon: "|", Pwd: "/", Expected: "/"},
{Style: Folder, FolderSeparatorIcon: "|", Pwd: homeDir, Expected: "~"}, {Style: Folder, FolderSeparatorIcon: "|", Pwd: homeDir, Expected: "~"},
{Style: Folder, FolderSeparatorIcon: "|", Pwd: homeDir, Expected: "someone", DisableMappedLocations: true}, {Style: Folder, FolderSeparatorIcon: "|", Pwd: homeDir, Expected: "someone", DisableMappedLocations: true},
{Style: Folder, FolderSeparatorIcon: "|", Pwd: homeDir + "/abc", Expected: "abc"}, {Style: Folder, FolderSeparatorIcon: "|", Pwd: homeDir + abc, Expected: "abc"},
{Style: Folder, FolderSeparatorIcon: "|", Pwd: "/a/b/c/d", Expected: "d"}, {Style: Folder, FolderSeparatorIcon: "|", Pwd: abcd, Expected: "d"},
// for Windows paths // for Windows paths
{Style: Folder, FolderSeparatorIcon: "\\", Pwd: "C:\\", Expected: "C:\\", PathSeparator: "\\", GOOS: platform.WINDOWS}, {Style: Folder, FolderSeparatorIcon: "\\", Pwd: "C:\\", Expected: "C:\\", PathSeparator: "\\", GOOS: platform.WINDOWS},
@ -806,41 +810,41 @@ func TestFullAndFolderPath(t *testing.T) {
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", StackCount: 2, Expected: "2 /"}, {Style: Full, FolderSeparatorIcon: "|", Pwd: "/", StackCount: 2, Expected: "2 /"},
{Style: Full, Pwd: "/", StackCount: 2, Expected: "2 /"}, {Style: Full, Pwd: "/", StackCount: 2, Expected: "2 /"},
{Style: Full, Pwd: homeDir, StackCount: 2, Expected: "2 ~"}, {Style: Full, Pwd: homeDir, StackCount: 2, Expected: "2 ~"},
{Style: Full, Pwd: homeDir + "/abc", StackCount: 2, Expected: "2 ~/abc"}, {Style: Full, Pwd: homeDir + abc, StackCount: 2, Expected: "2 ~/abc"},
{Style: Full, Pwd: homeDir + "/abc", StackCount: 2, Expected: "2 " + homeDir + "/abc", DisableMappedLocations: true}, {Style: Full, Pwd: homeDir + abc, StackCount: 2, Expected: "2 " + homeDir + abc, DisableMappedLocations: true},
{Style: Full, Pwd: "/a/b/c/d", StackCount: 2, Expected: "2 /a/b/c/d"}, {Style: Full, Pwd: abcd, StackCount: 2, Expected: "2 /a/b/c/d"},
// StackCountEnabled=false and StackCount=2 // StackCountEnabled=false and StackCount=2
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", Template: "{{ .Path }}", StackCount: 2, Expected: "/"}, {Style: Full, FolderSeparatorIcon: "|", Pwd: "/", Template: "{{ .Path }}", StackCount: 2, Expected: "/"},
{Style: Full, Pwd: "/", Template: "{{ .Path }}", StackCount: 2, Expected: "/"}, {Style: Full, Pwd: "/", Template: "{{ .Path }}", StackCount: 2, Expected: "/"},
{Style: Full, Pwd: homeDir, Template: "{{ .Path }}", StackCount: 2, Expected: "~"}, {Style: Full, Pwd: homeDir, Template: "{{ .Path }}", StackCount: 2, Expected: "~"},
{Style: Full, Pwd: homeDir + "/abc", Template: "{{ .Path }}", StackCount: 2, Expected: homeDir + "/abc", DisableMappedLocations: true}, {Style: Full, Pwd: homeDir + abc, Template: "{{ .Path }}", StackCount: 2, Expected: homeDir + abc, DisableMappedLocations: true},
{Style: Full, Pwd: "/a/b/c/d", Template: "{{ .Path }}", StackCount: 2, Expected: "/a/b/c/d"}, {Style: Full, Pwd: abcd, Template: "{{ .Path }}", StackCount: 2, Expected: abcd},
// StackCountEnabled=true and StackCount=0 // StackCountEnabled=true and StackCount=0
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", StackCount: 0, Expected: "/"}, {Style: Full, FolderSeparatorIcon: "|", Pwd: "/", StackCount: 0, Expected: "/"},
{Style: Full, Pwd: "/", StackCount: 0, Expected: "/"}, {Style: Full, Pwd: "/", StackCount: 0, Expected: "/"},
{Style: Full, Pwd: homeDir, StackCount: 0, Expected: "~"}, {Style: Full, Pwd: homeDir, StackCount: 0, Expected: "~"},
{Style: Full, Pwd: homeDir + "/abc", StackCount: 0, Expected: "~/abc"}, {Style: Full, Pwd: homeDir + abc, StackCount: 0, Expected: "~/abc"},
{Style: Full, Pwd: homeDir + "/abc", StackCount: 0, Expected: homeDir + "/abc", DisableMappedLocations: true}, {Style: Full, Pwd: homeDir + abc, StackCount: 0, Expected: homeDir + abc, DisableMappedLocations: true},
{Style: Full, Pwd: "/a/b/c/d", StackCount: 0, Expected: "/a/b/c/d"}, {Style: Full, Pwd: abcd, StackCount: 0, Expected: abcd},
// StackCountEnabled=true and StackCount<0 // StackCountEnabled=true and StackCount<0
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", StackCount: -1, Expected: "/"}, {Style: Full, FolderSeparatorIcon: "|", Pwd: "/", StackCount: -1, Expected: "/"},
{Style: Full, Pwd: "/", StackCount: -1, Expected: "/"}, {Style: Full, Pwd: "/", StackCount: -1, Expected: "/"},
{Style: Full, Pwd: homeDir, StackCount: -1, Expected: "~"}, {Style: Full, Pwd: homeDir, StackCount: -1, Expected: "~"},
{Style: Full, Pwd: homeDir + "/abc", StackCount: -1, Expected: "~/abc"}, {Style: Full, Pwd: homeDir + abc, StackCount: -1, Expected: "~/abc"},
{Style: Full, Pwd: homeDir + "/abc", StackCount: -1, Expected: homeDir + "/abc", DisableMappedLocations: true}, {Style: Full, Pwd: homeDir + abc, StackCount: -1, Expected: homeDir + abc, DisableMappedLocations: true},
{Style: Full, Pwd: "/a/b/c/d", StackCount: -1, Expected: "/a/b/c/d"}, {Style: Full, Pwd: abcd, StackCount: -1, Expected: abcd},
// StackCountEnabled=true and StackCount not set // StackCountEnabled=true and StackCount not set
{Style: Full, FolderSeparatorIcon: "|", Pwd: "/", Expected: "/"}, {Style: Full, FolderSeparatorIcon: "|", Pwd: "/", Expected: "/"},
{Style: Full, Pwd: "/", Expected: "/"}, {Style: Full, Pwd: "/", Expected: "/"},
{Style: Full, Pwd: homeDir, Expected: "~"}, {Style: Full, Pwd: homeDir, Expected: "~"},
{Style: Full, Pwd: homeDir + "/abc", Expected: "~/abc"}, {Style: Full, Pwd: homeDir + abc, Expected: "~/abc"},
{Style: Full, Pwd: homeDir + "/abc", Expected: homeDir + "/abc", DisableMappedLocations: true}, {Style: Full, Pwd: homeDir + abc, Expected: homeDir + abc, DisableMappedLocations: true},
{Style: Full, Pwd: "/a/b/c/d", Expected: "/a/b/c/d"}, {Style: Full, Pwd: abcd, Expected: abcd},
} }
for _, tc := range cases { for _, tc := range cases {
@ -895,14 +899,14 @@ func TestFullPathCustomMappedLocations(t *testing.T) {
PathSeparator string PathSeparator string
Expected string Expected string
}{ }{
{Pwd: "/a/b/c/d", MappedLocations: map[string]string{"{{ .Env.HOME }}/d": "#"}, Expected: "#"}, {Pwd: abcd, MappedLocations: map[string]string{"{{ .Env.HOME }}/d": "#"}, Expected: "#"},
{Pwd: "/a/b/c/d", MappedLocations: map[string]string{"/a/b/c/d": "#"}, Expected: "#"}, {Pwd: abcd, MappedLocations: map[string]string{abcd: "#"}, Expected: "#"},
{Pwd: "\\a\\b\\c\\d", MappedLocations: map[string]string{"\\a\\b": "#"}, GOOS: platform.WINDOWS, PathSeparator: "\\", Expected: "#\\c\\d"}, {Pwd: "\\a\\b\\c\\d", MappedLocations: map[string]string{"\\a\\b": "#"}, GOOS: platform.WINDOWS, PathSeparator: "\\", Expected: "#\\c\\d"},
{Pwd: "/a/b/c/d", MappedLocations: map[string]string{"/a/b": "#"}, Expected: "#/c/d"}, {Pwd: abcd, MappedLocations: map[string]string{"/a/b": "#"}, Expected: "#/c/d"},
{Pwd: "/a/b/c/d", MappedLocations: map[string]string{"/a/b": "/e/f"}, Expected: "/e/f/c/d"}, {Pwd: abcd, MappedLocations: map[string]string{"/a/b": "/e/f"}, Expected: "/e/f/c/d"},
{Pwd: homeDir + "/a/b/c/d", MappedLocations: map[string]string{"~/a/b": "#"}, Expected: "#/c/d"}, {Pwd: homeDir + abcd, MappedLocations: map[string]string{"~/a/b": "#"}, Expected: "#/c/d"},
{Pwd: "/a" + homeDir + "/b/c/d", MappedLocations: map[string]string{"/a~": "#"}, Expected: "/a" + homeDir + "/b/c/d"}, {Pwd: "/a" + homeDir + "/b/c/d", MappedLocations: map[string]string{"/a~": "#"}, Expected: "/a" + homeDir + "/b/c/d"},
{Pwd: homeDir + "/a/b/c/d", MappedLocations: map[string]string{"/a/b": "#"}, Expected: homeDir + "/a/b/c/d"}, {Pwd: homeDir + abcd, MappedLocations: map[string]string{"/a/b": "#"}, Expected: homeDir + abcd},
} }
for _, tc := range cases { for _, tc := range cases {
@ -975,7 +979,7 @@ func TestPowerlevelMappedLocations(t *testing.T) {
} }
func TestFolderPathCustomMappedLocations(t *testing.T) { func TestFolderPathCustomMappedLocations(t *testing.T) {
pwd := "/a/b/c/d" pwd := abcd
env := new(mock.MockedEnvironment) env := new(mock.MockedEnvironment)
env.On("PathSeparator").Return("/") env.On("PathSeparator").Return("/")
env.On("Home").Return(homeDir) env.On("Home").Return(homeDir)
@ -992,7 +996,7 @@ func TestFolderPathCustomMappedLocations(t *testing.T) {
props: properties.Map{ props: properties.Map{
properties.Style: Folder, properties.Style: Folder,
MappedLocations: map[string]string{ MappedLocations: map[string]string{
"/a/b/c/d": "#", abcd: "#",
}, },
}, },
} }
@ -1349,16 +1353,16 @@ func TestGetPwd(t *testing.T) {
{MappedLocationsEnabled: true, Pwd: homeDir + "-test", Expected: homeDir + "-test"}, {MappedLocationsEnabled: true, Pwd: homeDir + "-test", Expected: homeDir + "-test"},
{MappedLocationsEnabled: true}, {MappedLocationsEnabled: true},
{MappedLocationsEnabled: true, Pwd: "/usr", Expected: "/usr"}, {MappedLocationsEnabled: true, Pwd: "/usr", Expected: "/usr"},
{MappedLocationsEnabled: true, Pwd: homeDir + "/abc", Expected: "~/abc"}, {MappedLocationsEnabled: true, Pwd: homeDir + abc, Expected: "~/abc"},
{MappedLocationsEnabled: true, Pwd: "/a/b/c/d", Expected: "#"}, {MappedLocationsEnabled: true, Pwd: abcd, Expected: "#"},
{MappedLocationsEnabled: true, Pwd: "/a/b/c/d/e/f/g", Expected: "#/e/f/g"}, {MappedLocationsEnabled: true, Pwd: "/a/b/c/d/e/f/g", Expected: "#/e/f/g"},
{MappedLocationsEnabled: true, Pwd: "/z/y/x/w", Expected: "/z/y/x/w"}, {MappedLocationsEnabled: true, Pwd: "/z/y/x/w", Expected: "/z/y/x/w"},
{MappedLocationsEnabled: false}, {MappedLocationsEnabled: false},
{MappedLocationsEnabled: false, Pwd: homeDir + "/abc", Expected: homeDir + "/abc"}, {MappedLocationsEnabled: false, Pwd: homeDir + abc, Expected: homeDir + abc},
{MappedLocationsEnabled: false, Pwd: "/a/b/c/d/e/f/g", Expected: "#/e/f/g"}, {MappedLocationsEnabled: false, Pwd: "/a/b/c/d/e/f/g", Expected: "#/e/f/g"},
{MappedLocationsEnabled: false, Pwd: homeDir + "/c/d/e/f/g", Expected: homeDir + "/c/d/e/f/g"}, {MappedLocationsEnabled: false, Pwd: homeDir + cdefg, Expected: homeDir + cdefg},
{MappedLocationsEnabled: true, Pwd: homeDir + "/c/d/e/f/g", Expected: "~/c/d/e/f/g"}, {MappedLocationsEnabled: true, Pwd: homeDir + cdefg, Expected: "~/c/d/e/f/g"},
{MappedLocationsEnabled: true, Pwd: "/w/d/x/w", Pswd: "/z/y/x/w", Expected: "/z/y/x/w"}, {MappedLocationsEnabled: true, Pwd: "/w/d/x/w", Pswd: "/z/y/x/w", Expected: "/z/y/x/w"},
{MappedLocationsEnabled: false, Pwd: "/f/g/k/d/e/f/g", Pswd: "/a/b/c/d/e/f/g", Expected: "#/e/f/g"}, {MappedLocationsEnabled: false, Pwd: "/f/g/k/d/e/f/g", Pswd: "/a/b/c/d/e/f/g", Expected: "#/e/f/g"},
@ -1381,7 +1385,7 @@ func TestGetPwd(t *testing.T) {
props: properties.Map{ props: properties.Map{
MappedLocationsEnabled: tc.MappedLocationsEnabled, MappedLocationsEnabled: tc.MappedLocationsEnabled,
MappedLocations: map[string]string{ MappedLocations: map[string]string{
"/a/b/c/d": "#", abcd: "#",
}, },
}, },
} }
@ -1468,7 +1472,7 @@ func TestReplaceMappedLocations(t *testing.T) {
{Pwd: "/c/l/k/f", Expected: "f"}, {Pwd: "/c/l/k/f", Expected: "f"},
{Pwd: "/f/g/h", Expected: "/f/g/h"}, {Pwd: "/f/g/h", Expected: "/f/g/h"},
{Pwd: "/f/g/h/e", Expected: "^/e"}, {Pwd: "/f/g/h/e", Expected: "^/e"},
{Pwd: "/a/b/c/d", Expected: "#"}, {Pwd: abcd, Expected: "#"},
{Pwd: "/a/b/c/d/e", Expected: "#/e"}, {Pwd: "/a/b/c/d/e", Expected: "#/e"},
{Pwd: "/a/b/c/d/e", Expected: "#/e"}, {Pwd: "/a/b/c/d/e", Expected: "#/e"},
{Pwd: "/a/b/k/j/e", Expected: "e"}, {Pwd: "/a/b/k/j/e", Expected: "e"},
@ -1487,7 +1491,7 @@ func TestReplaceMappedLocations(t *testing.T) {
props: properties.Map{ props: properties.Map{
MappedLocationsEnabled: false, MappedLocationsEnabled: false,
MappedLocations: map[string]string{ MappedLocations: map[string]string{
"/a/b/c/d": "#", abcd: "#",
"/f/g/h/*": "^", "/f/g/h/*": "^",
"/c/l/k/*": "", "/c/l/k/*": "",
"~/j/*": "", "~/j/*": "",