From 67deabffda0cc477690f8b07633d1a8b579e4c87 Mon Sep 17 00:00:00 2001 From: Bohdan Dorokhin <24988081+dorokhin-bohdan@users.noreply.github.com> Date: Tue, 13 Aug 2024 09:21:55 +0300 Subject: [PATCH] fix(sitecore): replace HasFiles with HasFilesInDir --- src/segments/sitecore.go | 5 ++++- src/segments/sitecore_test.go | 5 ++++- src/test/sitecoreUser1.json | 10 ---------- src/test/sitecoreUser2.json | 10 ---------- 4 files changed, 8 insertions(+), 22 deletions(-) delete mode 100644 src/test/sitecoreUser1.json delete mode 100644 src/test/sitecoreUser2.json diff --git a/src/segments/sitecore.go b/src/segments/sitecore.go index 198fbb88..928d1995 100644 --- a/src/segments/sitecore.go +++ b/src/segments/sitecore.go @@ -33,13 +33,15 @@ type UserConfig struct { } func (s *Sitecore) Enabled() bool { - if !s.env.HasFiles(sitecoreFileName) || !s.env.HasFiles(path.Join(sitecoreFolderName, userFileName)) { + if !s.env.HasFiles(sitecoreFileName) || !s.env.HasFilesInDir(sitecoreFolderName, userFileName) { + s.env.Debug("sitecore cli configuration files were not found") return false } var userConfig, err = getUserConfig(s) if err != nil { + s.env.Error(err) return false } @@ -48,6 +50,7 @@ func (s *Sitecore) Enabled() bool { displayDefault := s.props.GetBool(properties.DisplayDefault, true) if !displayDefault && s.EndpointName == defaultEnpointName { + s.env.Debug("displaying of the default environment is turned off") return false } diff --git a/src/segments/sitecore_test.go b/src/segments/sitecore_test.go index 6797871c..2dbe5c30 100644 --- a/src/segments/sitecore_test.go +++ b/src/segments/sitecore_test.go @@ -8,6 +8,7 @@ import ( "github.com/jandedobbeleer/oh-my-posh/src/runtime/mock" "github.com/stretchr/testify/assert" + testify_ "github.com/stretchr/testify/mock" ) func TestSitecoreSegment(t *testing.T) { @@ -86,8 +87,10 @@ func TestSitecoreSegment(t *testing.T) { for _, tc := range cases { env := new(mock.Environment) env.On("HasFiles", "sitecore.json").Return(tc.SitecoreFileExists) - env.On("HasFiles", path.Join(".sitecore", "user.json")).Return(tc.UserFileExists) + env.On("HasFilesInDir", ".sitecore", "user.json").Return(tc.UserFileExists) env.On("FileContent", path.Join(".sitecore", "user.json")).Return(tc.UserFileContent) + env.On("Debug", testify_.Anything) + env.On("Error", testify_.Anything) props := properties.Map{ properties.DisplayDefault: tc.DisplayDefault, diff --git a/src/test/sitecoreUser1.json b/src/test/sitecoreUser1.json deleted file mode 100644 index 802948ad..00000000 --- a/src/test/sitecoreUser1.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "endpoints": { - "default": { - "ref": "xmcloud", - "allowWrite": true, - "host": "https://xmc-sitecore-projectName-environmentName.sitecorecloud.io", - "variables": {} - } - } -} diff --git a/src/test/sitecoreUser2.json b/src/test/sitecoreUser2.json deleted file mode 100644 index 7bcdf551..00000000 --- a/src/test/sitecoreUser2.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "endpoints": { - "default": { - "ref": "local", - "allowWrite": true, - "host": "https://xmcloudcm.local", - "variables": {} - } - } -}