Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Extracts sort from the list of providers for method list
Browse files Browse the repository at this point in the history
Signed-off-by: Bruna Tavares <bruna.silva@zup.com.br>
  • Loading branch information
brunasilvazup committed Jan 26, 2021
1 parent 51423db commit 2cc252b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 0 additions & 2 deletions pkg/cmd/add_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"reflect"
"sort"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -288,7 +287,6 @@ func (ar *addRepoCmd) resolveFlags(cmd *cobra.Command) (formula.Repo, error) {
}
}
if !providerValid {
sort.Strings(providers)
return formula.Repo{}, errors.New("please select a provider from " + strings.Join(providers, ", "))
}

Expand Down
6 changes: 1 addition & 5 deletions pkg/cmd/add_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package cmd

import (
"errors"
"sort"
"strings"
"testing"

Expand Down Expand Up @@ -46,9 +45,6 @@ func TestAddRepoCmd(t *testing.T) {
repoProviders.Add("GitLab", formula.Git{Repos: gitRepositoryWithoutTagsMock, NewRepoInfo: github.NewRepoInfo})
repoProviders.Add("Bitbucket", formula.Git{Repos: gitRepositoryErrorsMock, NewRepoInfo: github.NewRepoInfo})

repoProvidersSorted := repoProviders.List()
sort.Strings(repoProvidersSorted)

repoTest := &formula.Repo{
Provider: "Github",
Name: "someRepo1",
Expand Down Expand Up @@ -251,7 +247,7 @@ func TestAddRepoCmd(t *testing.T) {
name: "fail flags with wrong provider",
args: []string{"--provider=github"},
fields: fields{},
want: errors.New("please select a provider from " + strings.Join(repoProvidersSorted, ", ")),
want: errors.New("please select a provider from " + strings.Join(repoProviders.List(), ", ")),
},
{
name: "fail flags with empty name",
Expand Down
8 changes: 7 additions & 1 deletion pkg/formula/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

package formula

import "github.com/ZupIT/ritchie-cli/pkg/git"
import (
"sort"

"github.com/ZupIT/ritchie-cli/pkg/git"
)

const RepoCommonsName = RepoName("commons")

Expand Down Expand Up @@ -88,6 +92,8 @@ func (re RepoProviders) List() []string {
providers = append(providers, provider.String())
}

sort.Strings(providers)

return providers
}

Expand Down

0 comments on commit 2cc252b

Please sign in to comment.