Skip to content

Commit 6ca75e4

Browse files
Handles tkn pac list command when there is no repo in the namespace
Previously when there was no repo in a particular namespace, then using tkn pac list command it used to print just the headers Now with this patch it errors out saying `no repo found` Signed-off-by: PuneetPunamiya <[email protected]>
1 parent c2a874a commit 6ca75e4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

pkg/cmd/tknpac/list/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ func list(ctx context.Context, cs *params.Run, opts *cli.PacCliOpts, ioStreams *
163163
repoStatuses = append(repoStatuses, rs)
164164
}
165165

166+
if len(repoStatuses) == 0 {
167+
return fmt.Errorf("no repo found")
168+
}
169+
166170
w := ansiterm.NewTabWriter(ioStreams.Out, 0, 5, 3, ' ', tabwriter.TabIndent)
167171
colorScheme := ioStreams.ColorScheme()
168172
data := struct {

pkg/cmd/tknpac/list/list_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
testclient "github.com/openshift-pipelines/pipelines-as-code/pkg/test/clients"
2121
tektontest "github.com/openshift-pipelines/pipelines-as-code/pkg/test/tekton"
2222
tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
23+
"gotest.tools/v3/assert"
2324
"gotest.tools/v3/golden"
2425
corev1 "k8s.io/api/core/v1"
2526
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -120,8 +121,17 @@ func TestList(t *testing.T) {
120121
tests := []struct {
121122
name string
122123
args args
123-
wantErr bool
124+
wantErr string
124125
}{
126+
{
127+
name: "Test list when there are no repositories in the namespace",
128+
args: args{
129+
opts: &cli.PacCliOpts{
130+
Namespace: "default",
131+
},
132+
},
133+
wantErr: "no repo found",
134+
},
125135
{
126136
name: "Test list repositories only",
127137
args: args{
@@ -197,8 +207,8 @@ func TestList(t *testing.T) {
197207
cs.Clients.SetConsoleUI(consoleui.FallBackConsole{})
198208
io, out := newIOStream()
199209
if err := list(ctx, cs, tt.args.opts, io,
200-
cw, tt.args.selectors); (err != nil) != tt.wantErr {
201-
t.Errorf("describe() error = %v, wantErr %v", err, tt.wantErr)
210+
cw, tt.args.selectors); err != nil && tt.wantErr != "" {
211+
assert.Equal(t, err.Error(), tt.wantErr)
202212
} else {
203213
golden.Assert(t, out.String(), strings.ReplaceAll(fmt.Sprintf("%s.golden", t.Name()), "/", "-"))
204214
}

0 commit comments

Comments
 (0)