From 541420d6f0c2026fdcbbf7bbc5d92bdc7ab70d07 Mon Sep 17 00:00:00 2001 From: Rodrigo Campos Date: Mon, 12 Apr 2021 12:15:18 +0200 Subject: [PATCH] tests: add missing APILevelIsSupported() guard Commit "golang: Add support for SCMP_FLTATR_CTL_SSB" (276b0ea443de00461570ec512734ec0c3bc6cc42) added a call to GetAPI(), and is not guarded with "APILevelIsSupported()" to only report errors when it is supported. The rest of the added code had that, it is just missing for the GetAPI() part. This patch just adds a "APILevelIsSupported()" guard, as done in the rest of GetAPI() calls, to make sure it runs correctly with old libseccomp versions. Signed-off-by: Rodrigo Campos Acked-by: Tom Hromatka Signed-off-by: Paul Moore --- seccomp_test.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/seccomp_test.go b/seccomp_test.go index 7e5b8a5..92b0b31 100644 --- a/seccomp_test.go +++ b/seccomp_test.go @@ -464,13 +464,15 @@ func TestFilterAttributeGettersAndSetters(t *testing.T) { t.Errorf("Log bit was not set correctly") } - api, err := GetAPI() - if err != nil { - t.Errorf("Error getting API level: %s", err) - } else if api < 4 { - err = SetAPI(4) + if APILevelIsSupported() { + api, err := GetAPI() if err != nil { - t.Skipf("Skipping test: API level %d is less than 4", api) + t.Errorf("Error getting API level: %s", err) + } else if api < 4 { + err = SetAPI(4) + if err != nil { + t.Skipf("Skipping test: API level %d is less than 4", api) + } } }