RunTest executes a single test
(ctx context.Context, test v1alpha3.TestConfiguration, podSec bool)
| 220 | |
| 221 | // RunTest executes a single test |
| 222 | func (r PodTestRunner) RunTest(ctx context.Context, test v1alpha3.TestConfiguration, podSec bool) (*v1alpha3.TestStatus, error) { |
| 223 | |
| 224 | // Create a Pod to run the test |
| 225 | podDef := getPodDefinition(r.configMapName, test, r) |
| 226 | if podSec { |
| 227 | // creating a pod security context to support running in default namespace |
| 228 | podSecCtx := v1.PodSecurityContext{} |
| 229 | podSecCtx.RunAsNonRoot = &podSec |
| 230 | podSecCtx.SeccompProfile = &v1.SeccompProfile{ |
| 231 | Type: v1.SeccompProfileTypeRuntimeDefault, |
| 232 | } |
| 233 | |
| 234 | // creating a security context to be used by all containers in the pod |
| 235 | secCtx := v1.SecurityContext{} |
| 236 | secCtx.RunAsNonRoot = &podSec |
| 237 | secCtx.AllowPrivilegeEscalation = &[]bool{false}[0] |
| 238 | secCtx.Capabilities = &v1.Capabilities{ |
| 239 | Drop: []v1.Capability{ |
| 240 | "ALL", |
| 241 | }, |
| 242 | } |
| 243 | |
| 244 | podDef.Spec.SecurityContext = &podSecCtx |
| 245 | |
| 246 | podDef.Spec.Containers[0].SecurityContext = &secCtx |
| 247 | podDef.Spec.InitContainers[0].SecurityContext = &secCtx |
| 248 | } |
| 249 | |
| 250 | if test.Storage.Spec.MountPath.Path != "" { |
| 251 | addStorageToPod(podDef, test.Storage.Spec.MountPath.Path, r.StorageImage) |
| 252 | } |
| 253 | |
| 254 | pod, err := r.Client.CoreV1().Pods(r.Namespace).Create(ctx, podDef, metav1.CreateOptions{}) |
| 255 | if err != nil { |
| 256 | return nil, err |
| 257 | } |
| 258 | |
| 259 | err = r.waitForTestToComplete(ctx, pod) |
| 260 | if err != nil { |
| 261 | return nil, err |
| 262 | } |
| 263 | |
| 264 | // gather test output if necessary |
| 265 | if test.Storage.Spec.MountPath.Path != "" { |
| 266 | err := gatherTestOutput(r, test.Labels["suite"], test.Labels["test"], pod.Name, test.Storage.Spec.MountPath.Path) |
| 267 | if err != nil { |
| 268 | return nil, err |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | return r.getTestStatus(ctx, pod), nil |
| 273 | } |
| 274 | |
| 275 | // RunTest executes a single test |
| 276 | func (r FakeTestRunner) RunTest(ctx context.Context, _ v1alpha3.TestConfiguration, _ bool) (result *v1alpha3.TestStatus, err error) { |
nothing calls this directly
no test coverage detected