Merge pull request #30863 from mattfarina/list-tests

Adding test for list command
pull/30869/head
Matt Farina 4 months ago committed by GitHub
commit fbc153460f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -37,6 +37,9 @@ func newRepoListCmd(out io.Writer) *cobra.Command {
Args: require.NoArgs,
ValidArgsFunction: noMoreArgsCompFunc,
RunE: func(cmd *cobra.Command, _ []string) error {
// The error is silently ignored. If no repository file exists, it cannot be loaded,
// or the file isn't the right format to be parsed the error is ignored. The
// repositories will be 0.
f, _ := repo.LoadFile(settings.RepositoryConfig)
if len(f.Repositories) == 0 && outfmt != output.JSON && outfmt != output.YAML {
fmt.Fprintln(cmd.ErrOrStderr(), "no repositories to show")

@ -17,6 +17,8 @@ limitations under the License.
package cmd
import (
"fmt"
"path/filepath"
"testing"
)
@ -27,3 +29,26 @@ func TestRepoListOutputCompletion(t *testing.T) {
func TestRepoListFileCompletion(t *testing.T) {
checkFileCompletion(t, "repo list", false)
}
func TestRepoList(t *testing.T) {
rootDir := t.TempDir()
repoFile := filepath.Join(rootDir, "repositories.yaml")
repoFile2 := "testdata/repositories.yaml"
tests := []cmdTestCase{
{
name: "list with no repos",
cmd: fmt.Sprintf("repo list --repository-config %s --repository-cache %s", repoFile, rootDir),
golden: "output/repo-list-empty.txt",
wantError: false,
},
{
name: "list with repos",
cmd: fmt.Sprintf("repo list --repository-config %s --repository-cache %s", repoFile2, rootDir),
golden: "output/repo-list.txt",
wantError: false,
},
}
runTestCmd(t, tests)
}

@ -0,0 +1 @@
no repositories to show

@ -0,0 +1,4 @@
NAME URL
charts https://charts.helm.sh/stable
firstexample http://firstexample.com
secondexample http://secondexample.com
Loading…
Cancel
Save