summaryrefslogtreecommitdiff
path: root/cmd/podman/common/completion_test.go
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2022-05-12 13:08:03 +0200
committerPaul Holzinger <pholzing@redhat.com>2022-05-12 13:15:56 +0200
commit9df3906553fb78c32cd231e5de5de0074a181241 (patch)
treeac9acfc54b252effe770b79cddfa6ac42648950c /cmd/podman/common/completion_test.go
parent28588235d2051bf673d528c293261f926fad0d92 (diff)
downloadpodman-9df3906553fb78c32cd231e5de5de0074a181241.tar.gz
podman-9df3906553fb78c32cd231e5de5de0074a181241.tar.bz2
podman-9df3906553fb78c32cd231e5de5de0074a181241.zip
shell completion --format: work with pointer functions
The completion logic currently suggest also the functions that are defined for this type. However this did not work correctly when it was defined as pointer to that type on not the actual type. This commit fixes that problem. To test you can compare the difference between `podman stats --format {{.[TAB]` with and without this commit. 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.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/cmd/podman/common/completion_test.go b/cmd/podman/common/completion_test.go
index ae117a173..13f45a662 100644
--- a/cmd/podman/common/completion_test.go
+++ b/cmd/podman/common/completion_test.go
@@ -25,7 +25,9 @@ func (c Car) Type() string {
return ""
}
-func (c Car) Color() string {
+// Note: It is important that this function is *Car and the Type one is just Car.
+// The reflect logic behaves differently for these cases so we have to test both.
+func (c *Car) Color() string {
return ""
}
@@ -94,7 +96,7 @@ func TestAutocompleteFormat(t *testing.T) {
{
"second level struct field name",
"{{ .Car.",
- []string{"{{ .Car.Brand}}", "{{ .Car.Stats.", "{{ .Car.Extras}}", "{{ .Car.Color}}", "{{ .Car.Type}}"},
+ []string{"{{ .Car.Color}}", "{{ .Car.Type}}", "{{ .Car.Brand}}", "{{ .Car.Stats.", "{{ .Car.Extras}}"},
},
{
"second level struct field name",
@@ -104,7 +106,7 @@ func TestAutocompleteFormat(t *testing.T) {
{
"second level nil struct field name",
"{{ .Car2.",
- []string{"{{ .Car2.Brand}}", "{{ .Car2.Stats.", "{{ .Car2.Extras}}", "{{ .Car2.Color}}", "{{ .Car2.Type}}"},
+ []string{"{{ .Car2.Color}}", "{{ .Car2.Type}}", "{{ .Car2.Brand}}", "{{ .Car2.Stats.", "{{ .Car2.Extras}}"},
},
{
"three level struct field name",
@@ -134,8 +136,8 @@ func TestAutocompleteFormat(t *testing.T) {
{
"two variables struct field name",
"{{ .Car.Brand }} {{ .Car.",
- []string{"{{ .Car.Brand }} {{ .Car.Brand}}", "{{ .Car.Brand }} {{ .Car.Stats.", "{{ .Car.Brand }} {{ .Car.Extras}}",
- "{{ .Car.Brand }} {{ .Car.Color}}", "{{ .Car.Brand }} {{ .Car.Type}}"},
+ []string{"{{ .Car.Brand }} {{ .Car.Color}}", "{{ .Car.Brand }} {{ .Car.Type}}", "{{ .Car.Brand }} {{ .Car.Brand}}",
+ "{{ .Car.Brand }} {{ .Car.Stats.", "{{ .Car.Brand }} {{ .Car.Extras}}"},
},
{
"only dot without variable",