github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/internal/testutils/feature_test.go (about) 1 package testutils 2 3 import ( 4 "testing" 5 ) 6 7 func TestIgnoreKernelVersionCheckWhenEnvVarIsSet(t *testing.T) { 8 tests := []struct { 9 name string 10 toIgnoreNamesEnvValue string 11 testName string 12 ignoreKernelVersionCheck bool 13 }{ 14 { 15 name: "should NOT ignore kernel version check if environment var set to empty string", 16 toIgnoreNamesEnvValue: "", 17 testName: "TestABC", 18 ignoreKernelVersionCheck: false, 19 }, 20 { 21 name: "should ignore kernel version check if environment var set to skip test name with single value", 22 toIgnoreNamesEnvValue: "TestABC", 23 testName: "TestABC", 24 ignoreKernelVersionCheck: true, 25 }, 26 { 27 name: "should match test name when multiple comma separated names list is provided", 28 toIgnoreNamesEnvValue: "TestABC,TestXYZ", 29 testName: "TestXYZ", 30 ignoreKernelVersionCheck: true, 31 }, 32 { 33 name: "should NOT match test name when multiple comma separated names list is provided but name is not present in list", 34 toIgnoreNamesEnvValue: "TestABC,TestXYZ", 35 testName: "TestPQR", 36 ignoreKernelVersionCheck: false, 37 }, 38 { 39 name: "should match test name if names list has leading/trailing spaces", 40 toIgnoreNamesEnvValue: "TestABC, TestXYZ , TestPQR", 41 testName: "TestXYZ", 42 ignoreKernelVersionCheck: true, 43 }, 44 } 45 for _, tt := range tests { 46 t.Run(tt.name, func(t *testing.T) { 47 t.Setenv(ignoreKernelVersionEnvVar, tt.toIgnoreNamesEnvValue) 48 49 if got := ignoreKernelVersionCheck(tt.testName); got != tt.ignoreKernelVersionCheck { 50 t.Errorf("ignoreKernelVersionCheck() = %v, want %v", got, tt.ignoreKernelVersionCheck) 51 } 52 }) 53 } 54 }