Documentation
¶
Overview ¶
Package testcases defines various test case templates configurations.
Index ¶
- Constants
- Variables
- func GetOutRegExp(key RegExType) string
- func IsInFocus(focus []string, desc string) bool
- type BaseTestCase
- type BaseTestCaseConfigSpec
- type ConfiguredTest
- type ConfiguredTestCase
- type ContainerFact
- type ContainerFactType
- type RegExType
- type StatusFunctionType
- type TestAction
- type TestExpectedType
- type TestResultType
- type TestSpecType
Constants ¶
const ( // GatherFacts is name of the test case template for gathering pod facts GatherFacts = "GATHER_FACTS_POD" // PrivilegedPod is name of the test case template for running pod privilege tests PrivilegedPod = "PRIVILEGED_POD" // PrivilegedRoles is name of the test case template for running cluster roles and permission tests PrivilegedRoles = "PRIVILEGED_ROLE" // OperatorStatus checks if csv for a given operator is installed OperatorStatus = "OPERATOR_STATUS" )
Variables ¶
var CnfTestTemplateDataMap = map[string]string{ GatherFacts: cnf.GatherPodFactsJSON, PrivilegedPod: cnf.PrivilegedPodJSON, PrivilegedRoles: cnf.RolesJSON, }
CnfTestTemplateDataMap is map of available json data test case templates
var CnfTestTemplateFileMap = map[string]string{ PrivilegedPod: "privilegedpod.yml", PrivilegedRoles: "privilegedroles.yml", "ReadMeTxt": "readme.txt", }
CnfTestTemplateFileMap is map of configured test case filenames
var OperatorTestTemplateDataMap = map[string]string{ OperatorStatus: operator.OperatorJSON, }
OperatorTestTemplateDataMap is map of available json data test case templates
var OperatorTestTemplateFileMap = map[string]string{ OperatorStatus: "operatorstatus.yml", "ReadMeTxt": "readme.txt", }
OperatorTestTemplateFileMap is map of configured test case filenames
Functions ¶
func GetOutRegExp ¶
GetOutRegExp check and get available regular expression to parse
Types ¶
type BaseTestCase ¶
type BaseTestCase struct { // Name, Is the test case step name Name string `yaml:"name" json:"name"` // SkipTest, Is set to true by default. This is overridden in the test configuration file by defining test cases SkipTest bool `yaml:"skiptest" json:"skiptest"` // Loop, Indicates whether the testing resource has multiple objects to iterate and the number indicates how many iterable objects. // This value is set by gather facts test case Loop int `yaml:"loop" json:"loop"` // Command, Is the actual command to be executed on the testing subject Command string `yaml:"command" json:"command"` // ExpectedType, Is to identify what type of data is set in ExpectedStatus(function or string) ExpectedType TestExpectedType `yaml:"expectedtype" json:"expectedtype"` // ExpectedStatus, Is a list of strings that are expected to receive from the command execution ExpectedStatus []string `yaml:"expectedstatus" json:"expectedstatus"` // ResultType, Is the type of result that is expected from the execution of the command (String,Array, Int) ResultType TestResultType `default:"string" yaml:"resulttype" json:"resulttype"` // Action, Defines the type of action to be taken on the result (Allow or Deny) Action TestAction `yaml:"action" json:"action"` }
BaseTestCase spec of available test template
func (*BaseTestCase) ExpectedStatusFn ¶
func (b *BaseTestCase) ExpectedStatusFn(val string, fnType StatusFunctionType)
ExpectedStatusFn checks for expectedStatus function in the test template and replaces with data from container facts
func (*BaseTestCase) ReplaceSAasExpectedStatus ¶
func (b *BaseTestCase) ReplaceSAasExpectedStatus(index int, val string)
ReplaceSAasExpectedStatus replaces dynamic expected status defined in test template via function name
type BaseTestCaseConfigSpec ¶
type BaseTestCaseConfigSpec struct { // TestCase, Is the list of test cases that available along with their test steps TestCase []BaseTestCase `yaml:"testcase" json:"testcase"` }
BaseTestCaseConfigSpec slcie of test configurations template
func LoadCnfTestCaseSpecs ¶
func LoadCnfTestCaseSpecs(name string) (*BaseTestCaseConfigSpec, error)
LoadCnfTestCaseSpecs loads base test template data into a struct
func LoadOperatorTestCaseSpecs ¶
func LoadOperatorTestCaseSpecs(name string) (testCaseConfigSpec *BaseTestCaseConfigSpec, err error)
LoadOperatorTestCaseSpecs loads base test template data into a struct
func LoadTestCaseSpecsFromFile ¶
func LoadTestCaseSpecsFromFile(name, testCaseDir string, testSpecType TestSpecType) (*BaseTestCaseConfigSpec, error)
LoadTestCaseSpecsFromFile loads base test template files into a struct
type ConfiguredTest ¶
type ConfiguredTest struct { // Name of the configured tests. Name string `yaml:"name"` // Tests is a list of test steps under each Test case. Tests []string `yaml:"tests"` }
ConfiguredTest list all the test that are configured to run
func ContainsConfiguredTest ¶
func ContainsConfiguredTest(a []ConfiguredTest, testType string) ConfiguredTest
ContainsConfiguredTest checks whether configured test type is found.
func (*ConfiguredTest) RenderTestCaseSpec ¶
func (c *ConfiguredTest) RenderTestCaseSpec(testSpecType TestSpecType, testName string) (b *BaseTestCaseConfigSpec, err error)
RenderTestCaseSpec applies configured test case to template
type ConfiguredTestCase ¶
type ConfiguredTestCase struct { // CnfTest, Is the list of configured cnf test's that will be executed on the test subject CnfTest []ConfiguredTest `yaml:"cnftest"` // OperatorTest, Is the list of configured operator test that will be executed on the test subject OperatorTest []ConfiguredTest `yaml:"operatortest"` }
ConfiguredTestCase this loads the contents of testconfigured.yml file
func LoadConfiguredTestFile ¶
func LoadConfiguredTestFile(filepath string) (c *ConfiguredTestCase, err error)
LoadConfiguredTestFile loads configured test cases to struct
type ContainerFact ¶
type ContainerFact struct { // Name of the pod under test Name string // Namespace of the pod under test Namespace string // ServiceAccount name used by the pod ServiceAccount string // HasClusterRole if pod has cluster role HasClusterRole bool // ContainerCount is the count of containers inside the pod ContainerCount int // Exists if the pod is found in the cluster Exists bool }
ContainerFact struct to store pod facts
type ContainerFactType ¶
type ContainerFactType string
ContainerFactType type to hold container fact types
const ( // ServiceAccountName - for k8s service account name ServiceAccountName ContainerFactType = "SERVICE_ACCOUNT_NAME" // Name for pod name Name ContainerFactType = "NAME" // NameSpace for pod namespace NameSpace ContainerFactType = "NAMESPACE" // ClusterRole for cluster roles ClusterRole ContainerFactType = "CLUSTER_ROLE" // ContainerCount for count of containers in the pod ContainerCount ContainerFactType = "CONTAINER_COUNT" )
type RegExType ¶
type RegExType string
RegExType holds regex constant name.
const ( // AllowEmpty - Allows the result to match empty string AllowEmpty RegExType = "ALLOW_EMPTY" // AllowAll - Allows the result to match non empty string AllowAll RegExType = "allowAll" // EmptyNullFalse - Allows the result to match either empty,null or false string EmptyNullFalse RegExType = "EMPTY_NULL_FALSE" // NullFalse - Allows the result to match either null or false string NullFalse RegExType = "NULL_FALSE" // True - Allows the result to match `true` string True RegExType = "TRUE" // Null - Allows the result to match `null` string Null RegExType = "NULL" // Zero - Allows the result to match 0 number Zero RegExType = "ZERO" // NonZero - Allows the result to match non 0 number NonZero RegExType = "NON_ZERO" // Error - Allows the result to match error string Error RegExType = "ERROR" // Digit - Allows the result to match any number Digit RegExType = "DIGIT" )
type StatusFunctionType ¶
type StatusFunctionType string
StatusFunctionType type for holding function name for expected status in the test template
const ( // ServiceAccountFn function name to be called to replace expected status ServiceAccountFn StatusFunctionType = "FN_SERVICE_ACCOUNT_NAME" )
type TestAction ¶
type TestAction string
TestAction Action performed on the test result
const ( // Allow if the test result matches the expected result then allow Allow TestAction = "allow" // Deny if the test result matches the expected result then deny Deny TestAction = "deny" )
type TestExpectedType ¶
type TestExpectedType string
TestExpectedType defines what type is the value set for expected type
const ( // RegEx the result type will not be modified for regex RegEx TestExpectedType = "regex" // Function the expected result will be overridden by the function name defined under ExpectedType Function TestExpectedType = "function" // String the result type will not be modified for string String TestExpectedType = "string" )
type TestResultType ¶
type TestResultType string
TestResultType Defines Test Result Type
const ( // StringType the return result is of type string StringType TestResultType = "string" // ArrayType the return result is of type array ArrayType TestResultType = "array" // IntType the return result is of type int IntType TestResultType = "int" )
type TestSpecType ¶
type TestSpecType string
TestSpecType defines spec type is of type Operator or CNF
const ( // Operator to load operator spec from config Operator TestSpecType = "operator" // Cnf to load CNF spec from config Cnf TestSpecType = "CNF" )