summaryrefslogtreecommitdiff
path: root/pkg/util
diff options
context:
space:
mode:
authorJakub Guzik <jakubmguzik@gmail.com>2021-03-24 00:42:42 +0100
committerJakub Guzik <jakubmguzik@gmail.com>2021-03-24 00:56:00 +0100
commit914218c1e8fd0dc11c1caee807bbed0cf26fdaf8 (patch)
tree4af0786346f704b0ea0765d34ea52740b622e5ba /pkg/util
parent5eab1b07428e4078bd15ca5b69f28f2733850cdd (diff)
downloadpodman-914218c1e8fd0dc11c1caee807bbed0cf26fdaf8.tar.gz
podman-914218c1e8fd0dc11c1caee807bbed0cf26fdaf8.tar.bz2
podman-914218c1e8fd0dc11c1caee807bbed0cf26fdaf8.zip
Unification of until filter across list/prune endpoints
Signed-off-by: Jakub Guzik <jakubmguzik@gmail.com>
Diffstat (limited to 'pkg/util')
-rw-r--r--pkg/util/filters.go4
-rw-r--r--pkg/util/filters_test.go38
2 files changed, 39 insertions, 3 deletions
diff --git a/pkg/util/filters.go b/pkg/util/filters.go
index 90daef402..43bf646f1 100644
--- a/pkg/util/filters.go
+++ b/pkg/util/filters.go
@@ -12,10 +12,10 @@ import (
)
// ComputeUntilTimestamp extracts until timestamp from filters
-func ComputeUntilTimestamp(filter string, filterValues []string) (time.Time, error) {
+func ComputeUntilTimestamp(filterValues []string) (time.Time, error) {
invalid := time.Time{}
if len(filterValues) != 1 {
- return invalid, errors.Errorf("specify exactly one timestamp for %s", filter)
+ return invalid, errors.Errorf("specify exactly one timestamp for until")
}
ts, err := timetype.GetTimestamp(filterValues[0], time.Now())
if err != nil {
diff --git a/pkg/util/filters_test.go b/pkg/util/filters_test.go
index 4771f682b..47259013e 100644
--- a/pkg/util/filters_test.go
+++ b/pkg/util/filters_test.go
@@ -1,6 +1,8 @@
package util
-import "testing"
+import (
+ "testing"
+)
func TestMatchLabelFilters(t *testing.T) {
testLabels := map[string]string{
@@ -75,3 +77,37 @@ func TestMatchLabelFilters(t *testing.T) {
})
}
}
+
+func TestComputeUntilTimestamp(t *testing.T) {
+ tests := []struct {
+ name string
+ args []string
+ wantErr bool
+ }{
+ {
+ name: "Return error when more values in list",
+ args: []string{"5h", "6s"},
+ wantErr: true,
+ },
+ {
+ name: "Return error when invalid time",
+ args: []string{"invalidTime"},
+ wantErr: true,
+ },
+ {
+ name: "Do not return error when correct time format supplied",
+ args: []string{"44m"},
+ wantErr: false,
+ },
+ }
+ for _, tt := range tests {
+ tt := tt
+ t.Run(tt.name, func(t *testing.T) {
+ _, err := ComputeUntilTimestamp(tt.args)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("ComputeUntilTimestamp() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ })
+ }
+}