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