summaryrefslogtreecommitdiff
path: root/cmd/podman/common/completion_test.go
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2022-05-16 16:50:07 +0200
committerPaul Holzinger <pholzing@redhat.com>2022-05-18 18:28:11 +0200
commitecd6edb19186b43c064a09b0a824732ff5f5242e (patch)
tree85c259bee9f2cb08179ae1671b52b9383fe6e763 /cmd/podman/common/completion_test.go
parent11ff5ffd3b0acba02991b0879a1b8493ea0f3bc9 (diff)
downloadpodman-ecd6edb19186b43c064a09b0a824732ff5f5242e.tar.gz
podman-ecd6edb19186b43c064a09b0a824732ff5f5242e.tar.bz2
podman-ecd6edb19186b43c064a09b0a824732ff5f5242e.zip
shell completion --format: fix embedded struct handling
When a struct is embeeded it is possible that we end up with same names but different types, this results in incorrect completions. The go template logic always preferes the actual field/method name before the one from the embedded one. Thefore the completion logic should do the same. First get all method/fields names from the struct and then only add the field names from the embedded struct when they are not already present in the list. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'cmd/podman/common/completion_test.go')
-rw-r--r--cmd/podman/common/completion_test.go21
1 files changed, 16 insertions, 5 deletions
diff --git a/cmd/podman/common/completion_test.go b/cmd/podman/common/completion_test.go
index 63b99501f..34ec9b6a5 100644
--- a/cmd/podman/common/completion_test.go
+++ b/cmd/podman/common/completion_test.go
@@ -19,6 +19,17 @@ type Car struct {
type Anonymous struct {
Hello string
+ // The name should match the testStruct Name below. This is used to make
+ // sure the logic uses the actual struct fields before the embedded ones.
+ Name struct {
+ Suffix string
+ Prefix string
+ }
+}
+
+// The name should match the testStruct Age name below.
+func (a Anonymous) Age() int {
+ return 0
}
func (c Car) Type() string {
@@ -87,17 +98,17 @@ func TestAutocompleteFormat(t *testing.T) {
{
"invalid completion",
"{{ ..",
- nil,
+ []string{},
},
{
"fist level struct field name",
"{{.",
- []string{"{{.Name}}", "{{.Age}}", "{{.Car.", "{{.Car2.", "{{.Hello}}"},
+ []string{"{{.Name}}", "{{.Age}}", "{{.Car.", "{{.Car2.", "{{.Anonymous.", "{{.Hello}}"},
},
{
"fist level struct field name",
"{{ .",
- []string{"{{ .Name}}", "{{ .Age}}", "{{ .Car.", "{{ .Car2.", "{{ .Hello}}"},
+ []string{"{{ .Name}}", "{{ .Age}}", "{{ .Car.", "{{ .Car2.", "{{ .Anonymous.", "{{ .Hello}}"},
},
{
"fist level struct field name",
@@ -137,12 +148,12 @@ func TestAutocompleteFormat(t *testing.T) {
{
"invalid field name",
"{{ .Ca.B",
- nil,
+ []string{},
},
{
"map key names don't work",
"{{ .Car.Extras.",
- nil,
+ []string{},
},
{
"two variables struct field name",