mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 04:54:03 -08:00
fix(az): proper path fix
This commit is contained in:
parent
7aaae67a77
commit
4542e92940
|
@ -102,11 +102,6 @@ func (a *az) enabled() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *az) getFileContentWithoutBom(file string) string {
|
func (a *az) getFileContentWithoutBom(file string) string {
|
||||||
azFolder := ".azure"
|
|
||||||
if a.env.getRuntimeGOOS() == linuxPlatform {
|
|
||||||
azFolder = ".Azure"
|
|
||||||
}
|
|
||||||
file = filepath.Join(a.env.homeDir(), azFolder, file)
|
|
||||||
config := a.env.getFileContent(file)
|
config := a.env.getFileContent(file)
|
||||||
const ByteOrderMark = "\ufeff"
|
const ByteOrderMark = "\ufeff"
|
||||||
return strings.TrimLeft(config, ByteOrderMark)
|
return strings.TrimLeft(config, ByteOrderMark)
|
||||||
|
@ -114,7 +109,8 @@ func (a *az) getFileContentWithoutBom(file string) string {
|
||||||
|
|
||||||
func (a *az) getAzureProfile() bool {
|
func (a *az) getAzureProfile() bool {
|
||||||
var content string
|
var content string
|
||||||
if content = a.getFileContentWithoutBom("azureProfile.json"); len(content) == 0 {
|
profile := filepath.Join(a.env.homeDir(), ".azure", "azureProfile.json")
|
||||||
|
if content = a.getFileContentWithoutBom(profile); len(content) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
var config AzureConfig
|
var config AzureConfig
|
||||||
|
@ -133,7 +129,16 @@ func (a *az) getAzureProfile() bool {
|
||||||
|
|
||||||
func (a *az) getAzureRmContext() bool {
|
func (a *az) getAzureRmContext() bool {
|
||||||
var content string
|
var content string
|
||||||
if content = a.getFileContentWithoutBom("AzureRmContext.json"); len(content) == 0 {
|
profiles := []string{
|
||||||
|
filepath.Join(a.env.homeDir(), ".azure", "AzureRmContext.json"),
|
||||||
|
filepath.Join(a.env.homeDir(), ".Azure", "AzureRmContext.json"),
|
||||||
|
}
|
||||||
|
for _, profile := range profiles {
|
||||||
|
if content = a.getFileContentWithoutBom(profile); len(content) != 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(content) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
var config AzurePowerShellConfig
|
var config AzurePowerShellConfig
|
||||||
|
|
|
@ -15,6 +15,7 @@ func TestAzSegment(t *testing.T) {
|
||||||
ExpectedString string
|
ExpectedString string
|
||||||
HasCLI bool
|
HasCLI bool
|
||||||
HasPowerShell bool
|
HasPowerShell bool
|
||||||
|
HasPowerShellUnix bool
|
||||||
Template string
|
Template string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -35,6 +36,13 @@ func TestAzSegment(t *testing.T) {
|
||||||
Template: "{{ .EnvironmentName }}",
|
Template: "{{ .EnvironmentName }}",
|
||||||
HasPowerShell: true,
|
HasPowerShell: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Case: "Az Pwsh Profile",
|
||||||
|
ExpectedEnabled: true,
|
||||||
|
ExpectedString: "AzurePoshCloud",
|
||||||
|
Template: "{{ .EnvironmentName }}",
|
||||||
|
HasPowerShellUnix: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Case: "Faulty template",
|
Case: "Faulty template",
|
||||||
ExpectedEnabled: true,
|
ExpectedEnabled: true,
|
||||||
|
@ -62,7 +70,7 @@ func TestAzSegment(t *testing.T) {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
home := "/Users/posh"
|
home := "/Users/posh"
|
||||||
env.On("homeDir", nil).Return(home)
|
env.On("homeDir", nil).Return(home)
|
||||||
var azureProfile, azureRmContext string
|
var azureProfile, azureRmContext, azureRMContext string
|
||||||
if tc.HasCLI {
|
if tc.HasCLI {
|
||||||
content, _ := ioutil.ReadFile("./test/azureProfile.json")
|
content, _ := ioutil.ReadFile("./test/azureProfile.json")
|
||||||
azureProfile = string(content)
|
azureProfile = string(content)
|
||||||
|
@ -71,9 +79,14 @@ func TestAzSegment(t *testing.T) {
|
||||||
content, _ := ioutil.ReadFile("./test/AzureRmContext.json")
|
content, _ := ioutil.ReadFile("./test/AzureRmContext.json")
|
||||||
azureRmContext = string(content)
|
azureRmContext = string(content)
|
||||||
}
|
}
|
||||||
|
if tc.HasPowerShellUnix {
|
||||||
|
content, _ := ioutil.ReadFile("./test/AzureRmContext.json")
|
||||||
|
azureRMContext = string(content)
|
||||||
|
}
|
||||||
env.On("getRuntimeGOOS", nil).Return(linuxPlatform)
|
env.On("getRuntimeGOOS", nil).Return(linuxPlatform)
|
||||||
env.On("getFileContent", filepath.Join(home, ".Azure", "azureProfile.json")).Return(azureProfile)
|
env.On("getFileContent", filepath.Join(home, ".azure", "azureProfile.json")).Return(azureProfile)
|
||||||
env.On("getFileContent", filepath.Join(home, ".Azure", "AzureRmContext.json")).Return(azureRmContext)
|
env.On("getFileContent", filepath.Join(home, ".Azure", "AzureRmContext.json")).Return(azureRmContext)
|
||||||
|
env.On("getFileContent", filepath.Join(home, ".azure", "AzureRmContext.json")).Return(azureRMContext)
|
||||||
env.onTemplate()
|
env.onTemplate()
|
||||||
props := properties{
|
props := properties{
|
||||||
SegmentTemplate: tc.Template,
|
SegmentTemplate: tc.Template,
|
||||||
|
|
Loading…
Reference in a new issue