From 33706fa4abb99ee1f665da80d30f9d19b595dfc9 Mon Sep 17 00:00:00 2001 From: Jiri Olsa Date: Thu, 4 Apr 2024 14:16:22 +0000 Subject: [PATCH] tetragon: Add ParseCgroupRate test Adding test for ParseCgroupRate function. Signed-off-by: Jiri Olsa --- pkg/cgrouprate/cgrouprate_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pkg/cgrouprate/cgrouprate_test.go b/pkg/cgrouprate/cgrouprate_test.go index 0d1c8835677..d86c6992dec 100644 --- a/pkg/cgrouprate/cgrouprate_test.go +++ b/pkg/cgrouprate/cgrouprate_test.go @@ -257,3 +257,26 @@ func TestProcessCgroup(t *testing.T) { assert.Equal(t, d.throttle, l.throttle) } } + +func TestParseCgroupRate(t *testing.T) { + var opt option.CgroupRate + + // ok + opt = option.ParseCgroupRate("1,1s") + assert.Equal(t, option.CgroupRate{Events: 1, Interval: 1000000000}, opt) + + opt = option.ParseCgroupRate("1,1m") + assert.Equal(t, option.CgroupRate{Events: 1, Interval: 60000000000}, opt) + + // fail + empty := option.CgroupRate{Events: 0, Interval: 0} + + opt = option.ParseCgroupRate("10") + assert.Equal(t, empty, opt) + + opt = option.ParseCgroupRate("sure,1s") + assert.Equal(t, empty, opt) + + opt = option.ParseCgroupRate("1,nope") + assert.Equal(t, empty, opt) +}