Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/cmd/tknpac/info/templates/info.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
Webhook URL: {{ .Info.HookConfig.URL }}
{{- end }}
{{- end }}
{{- if (gt (len .Repos) 1) }}
{{- if (gt (len .Repos) 0) }}

{{ $.CS.Underline "Repositories CR" }}: {{ len .Repos }}
Namespace URL
Expand Down
2 changes: 1 addition & 1 deletion pkg/params/info/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (k *KubeOpts) AddFlags(cmd *cobra.Command) {
fmt.Sprintf("Path to the kubeconfig file to use for CLI requests (default: %s)", envkconfig))

cmd.PersistentFlags().StringVarP(
&k.ConfigPath,
&k.Namespace,
"namespace", "n", "",
"If present, the namespace scope for this CLI request")
}
55 changes: 55 additions & 0 deletions pkg/params/info/kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,58 @@ func TestKubeOptsWithEnv(t *testing.T) {
})
}
}

func TestKubeOptsFlags(t *testing.T) {
t.Setenv("HOME", "/home/user")
t.Setenv("KUBECONFIG", "")
defaultKubeconfigPath := "/home/user/.kube/config"
customKubeconfigPath := "/custom/kube/config"

testcases := []struct {
name string
flags []string
expectNS string
expectCfg string
}{
{
name: "namespace flag only",
flags: []string{"--namespace", "test-ns"},
expectNS: "test-ns",
expectCfg: defaultKubeconfigPath,
},
{
name: "namespace flag short form",
flags: []string{"-n", "test-ns"},
expectNS: "test-ns",
expectCfg: defaultKubeconfigPath,
},
{
name: "kubeconfig flag only",
flags: []string{"--kubeconfig", customKubeconfigPath},
expectNS: "",
expectCfg: customKubeconfigPath,
},
{
name: "both flags together",
flags: []string{"--namespace", "test-ns", "--kubeconfig", customKubeconfigPath},
expectNS: "test-ns",
expectCfg: customKubeconfigPath,
},
{
name: "both flags short form",
flags: []string{"-n", "test-ns", "-k", customKubeconfigPath},
expectNS: "test-ns",
expectCfg: customKubeconfigPath,
},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
k := &KubeOpts{}
cmd := &cobra.Command{}
k.AddFlags(cmd)
assert.NilError(t, cmd.ParseFlags(tc.flags))
assert.Equal(t, k.Namespace, tc.expectNS, "namespace mismatch")
assert.Equal(t, k.ConfigPath, tc.expectCfg, "config path mismatch")
})
}
}