This commit is contained in:
Guillaume Tardif 2020-06-18 18:13:34 +02:00
parent d6084e1b6e
commit e99e3aefc5
2 changed files with 7 additions and 3 deletions

View File

@ -147,12 +147,12 @@ func (helper contextCreateACIHelper) chooseGroup(ctx context.Context, subscripti
func (helper contextCreateACIHelper) chooseSub(subs []subscription.Model) (string, error) {
if len(subs) == 1 {
sub := subs[0]
fmt.Println("Using only available subscription : " + *sub.DisplayName + "(" + *sub.SubscriptionID + ")")
fmt.Println("Using only available subscription : " + display(sub))
return *sub.SubscriptionID, nil
}
var options []string
for _, sub := range subs {
options = append(options, *sub.DisplayName+"("+*sub.SubscriptionID+")")
options = append(options, display(sub))
}
selected, err := helper.selector.userSelect("Select a subscription ID", options)
if err != nil {
@ -164,6 +164,10 @@ func (helper contextCreateACIHelper) chooseSub(subs []subscription.Model) (strin
return *subs[selected].SubscriptionID, nil
}
func display(sub subscription.Model) string {
return fmt.Sprintf("%s (%s)", *sub.DisplayName, *sub.SubscriptionID)
}
type userSelector interface {
userSelect(message string, options []string) (int, error)
}

View File

@ -121,7 +121,7 @@ func (suite *ContextSuiteTest) TestSelectSubscriptionIdAndExistingResourceGroup(
suite.mockResourceGroupHeper.On("GetSubscriptionIDs", ctx).Return([]subscription.Model{sub1, sub2}, nil)
selectOptions := []string{"Subscription1(1234)", "Subscription2(5678)"}
selectOptions := []string{"Subscription1 (1234)", "Subscription2 (5678)"}
suite.mockUserSelector.On("userSelect", "Select a subscription ID", selectOptions).Return(1, nil)
selectOptions = []string{"create a new resource group", "group1 (eastus)", "group2 (westeurope)"}
suite.mockUserSelector.On("userSelect", "Select a resource group", selectOptions).Return(2, nil)