Skip to content

Commit

Permalink
feat: display message on az update needed
Browse files Browse the repository at this point in the history
resolves #669
  • Loading branch information
JanDeDobbeleer committed Apr 22, 2021
1 parent 44ac09d commit fb57ef1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 29 deletions.
11 changes: 11 additions & 0 deletions src/segment_az.go
Expand Up @@ -19,6 +19,11 @@ const (
DisplaySubscriptionID Property = "display_id"
// DisplaySubscriptionName hides or shows the subscription display name
DisplaySubscriptionName Property = "display_name"

updateConsentNeeded = "Do you want to continue?"
updateMessage = "AZ CLI: Update needed!"
updateForeground = "#ffffff"
updateBackground = "#ff5349"
)

func (a *az) string() string {
Expand Down Expand Up @@ -68,6 +73,12 @@ func (a *az) getFromAzCli() (string, string, bool) {
return "", "", false
}

if strings.Contains(output, updateConsentNeeded) {
a.props.foreground = updateForeground
a.props.background = updateBackground
return updateMessage, "", true
}

splittedOutput := strings.Split(output, "\n")
if len(splittedOutput) < 2 {
return "", "", false
Expand Down
70 changes: 41 additions & 29 deletions src/segment_az_test.go
Expand Up @@ -21,86 +21,98 @@ func TestAzSegment(t *testing.T) {
DisplayID bool
DisplayName bool
}{
{Case: "envvars present",
{
Case: "envvars present",
ExpectedEnabled: true,
ExpectedString: "foo$bar",
EnvSubName: "foo",
EnvSubID: "bar",
CliExists: false,
InfoSeparator: "$",
DisplayID: true,
DisplayName: true},
{Case: "envvar name present",
DisplayName: true,
},
{
Case: "envvar name present",
ExpectedEnabled: true,
ExpectedString: "foo$",
EnvSubName: "foo",
EnvSubID: "",
CliExists: false,
InfoSeparator: "$",
DisplayID: true,
DisplayName: true},
{Case: "envvar id present",
DisplayName: true,
},
{
Case: "envvar id present",
ExpectedEnabled: true,
ExpectedString: "$bar",
EnvSubName: "",
EnvSubID: "bar",
CliExists: false,
InfoSeparator: "$",
DisplayID: true,
DisplayName: true},
{Case: "cli not found",
DisplayName: true,
},
{
Case: "cli not found",
ExpectedEnabled: false,
ExpectedString: "$",
EnvSubName: "",
EnvSubID: "",
CliExists: false,
InfoSeparator: "$",
DisplayID: true,
DisplayName: true},
{Case: "cli contains data",
DisplayName: true,
},
{
Case: "cli contains data",
ExpectedEnabled: true,
ExpectedString: "foo$bar",
EnvSubName: "",
EnvSubID: "",
CliExists: true,
CliSubName: "foo",
CliSubID: "bar",
InfoSeparator: "$",
DisplayID: true,
DisplayName: true},
{Case: "print only name",
DisplayName: true,
},
{
Case: "print only name",
ExpectedEnabled: true,
ExpectedString: "foo",
EnvSubName: "",
EnvSubID: "",
CliExists: true,
CliSubName: "foo",
CliSubID: "bar",
InfoSeparator: "$",
DisplayID: false,
DisplayName: true},
{Case: "print only id",
DisplayName: true,
},
{
Case: "print only id",
ExpectedEnabled: true,
ExpectedString: "bar",
EnvSubName: "",
EnvSubID: "",
CliExists: true,
CliSubName: "foo",
CliSubID: "bar",
InfoSeparator: "$",
DisplayID: true,
DisplayName: false},
{Case: "print none",
DisplayName: false,
},
{
Case: "print none",
ExpectedEnabled: false,
ExpectedString: "",
EnvSubName: "",
EnvSubID: "",
CliExists: true,
CliSubName: "foo",
CliSubID: "bar",
InfoSeparator: "$",
DisplayID: false,
DisplayName: false},
DisplayName: false,
},
{
Case: "update needed",
ExpectedEnabled: true,
ExpectedString: updateMessage,
CliExists: true,
CliSubName: "Do you want to continue? (Y/n): Visual Studio Enterprise",
DisplayID: false,
DisplayName: true,
},
}

for _, tc := range cases {
Expand Down

0 comments on commit fb57ef1

Please sign in to comment.