Repository: JanDeDobbeleer/oh-my-posh
Pull request #5447 (2024-08-12 10:34:38)

fix(Sitecore): replace HasFiles with HasFilesInDir for user.json file…
… (#5)

* fix(Sitecore): replace HasFiles with HasFilesInDir for user.json file

* fix(Sitecore): remove useless test files

---------

### Prerequisites

- [x] I have read and understood the [contributing guide][CONTRIBUTING.md].
- [x] The commit message follows the [conventional commits][cc] guidelines.
- [x] Tests for the changes have been added (for bug fixes / features).
- [x] Docs have been added/updated (for bug fixes / features).

### Description

The Sitecore segment was not displayed in a properly configured directory.
The `HasFiles` method returns `false` for `path.Join(sitecoreFolderName, userFileName)` argument while `HasFilesInDir` returns `true` (expected result). 

![image](https://github.com/user-attachments/assets/c533ca67-92be-4ceb-988d-c3dbdee153ca)

<!---

Tips:

If you're not comfortable with working with Git,
we're working a guide (https://ohmyposh.dev/docs/contributing/git) to help you out.
Oh My Posh advises GitKraken (https://www.gitkraken.com/invite/nQmDPR9D) as your preferred cross platform Git GUI power tool.

-->

[CONTRIBUTING.md]: https://github.com/JanDeDobbeleer/oh-my-posh/blob/main/CONTRIBUTING.md
[cc]: https://www.conventionalcommits.org/en/v1.0.0/#summary



Patch:
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
 	}
 


Test patch:
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<someID>-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": {}
-    }
-  }
-}