mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-10 13:04:04 -08:00
feat(gcp): remove .Error
aligns the segment with az and aws, relates to #2810 BREAKING CHANGE: this removes the .Error field from the segment template which means anyone with a custom template in the gcp segment needs to remove it from their template. The new default template is: `" {{ .Project }} "`
This commit is contained in:
parent
086260a5af
commit
7ea921351f
|
@ -17,11 +17,10 @@ type Gcp struct {
|
|||
Account string
|
||||
Project string
|
||||
Region string
|
||||
Error string
|
||||
}
|
||||
|
||||
func (g *Gcp) Template() string {
|
||||
return " {{ if not .Error }}{{ .Project }}{{ end }} "
|
||||
return " {{ .Project }} "
|
||||
}
|
||||
|
||||
func (g *Gcp) Init(props properties.Properties, env environment.Environment) {
|
||||
|
@ -33,16 +32,16 @@ func (g *Gcp) Enabled() bool {
|
|||
cfgDir := g.getConfigDirectory()
|
||||
configFile, err := g.getActiveConfig(cfgDir)
|
||||
if err != nil {
|
||||
g.Error = err.Error()
|
||||
return true
|
||||
g.env.Log(environment.Error, "Gcp.Enabled()", err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
cfgpath := path.Join(cfgDir, "configurations", "config_"+configFile)
|
||||
|
||||
cfg, err := ini.Load(cfgpath)
|
||||
if err != nil {
|
||||
g.Error = "GCLOUD CONFIG ERROR"
|
||||
return true
|
||||
g.env.Log(environment.Error, "Gcp.Enabled()", err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
g.Project = cfg.Section("core").Key("project").String()
|
||||
|
|
|
@ -5,9 +5,11 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"oh-my-posh/environment"
|
||||
"oh-my-posh/mock"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
mock2 "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
func TestGcpSegment(t *testing.T) {
|
||||
|
@ -35,16 +37,11 @@ func TestGcpSegment(t *testing.T) {
|
|||
Template: standardTemplate,
|
||||
ConfigPath: "../invalid/",
|
||||
ActiveConfig: "nofile",
|
||||
ExpectedEnabled: true,
|
||||
ExpectedString: "GCLOUD CONFIG ERROR",
|
||||
},
|
||||
{
|
||||
Case: "invalid active config file",
|
||||
Template: standardTemplate,
|
||||
ConfigPath: "../invalid/",
|
||||
ActiveConfig: "",
|
||||
ExpectedEnabled: true,
|
||||
ExpectedString: "NO ACTIVE CONFIG FOUND",
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -53,10 +50,13 @@ func TestGcpSegment(t *testing.T) {
|
|||
env.On("Getenv", "CLOUDSDK_CONFIG").Return(tc.ConfigPath)
|
||||
fcPath, _ := filepath.Abs(path.Join(tc.ConfigPath, "active_config"))
|
||||
env.On("FileContent", fcPath).Return(tc.ActiveConfig)
|
||||
env.On("Log", environment.Error, "Gcp.Enabled()", mock2.Anything).Return()
|
||||
g := &Gcp{
|
||||
env: env,
|
||||
}
|
||||
assert.Equal(t, tc.ExpectedEnabled, g.Enabled(), tc.Case)
|
||||
if tc.ExpectedEnabled {
|
||||
assert.Equal(t, tc.ExpectedString, renderTemplate(env, tc.Template, g), tc.Case)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue