mirror of https://github.com/helm/helm.git
Merge pull request #30863 from mattfarina/list-tests
build-test / build (push) Has been cancelled
Details
CodeQL / Analyze (go) (push) Has been cancelled
Details
golangci-lint / golangci-lint (push) Has been cancelled
Details
release / release (push) Has been cancelled
Details
release / canary-release (push) Has been cancelled
Details
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Details
build-test / build (push) Has been cancelled
Details
CodeQL / Analyze (go) (push) Has been cancelled
Details
golangci-lint / golangci-lint (push) Has been cancelled
Details
release / release (push) Has been cancelled
Details
release / canary-release (push) Has been cancelled
Details
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Details
Adding test for list command
This commit is contained in:
commit
fbc153460f
|
@ -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…
Reference in New Issue