|
| 1 | +# Adding declarative tests |
| 2 | + |
| 3 | +Declarative tests are for simple tests to check for OCP resource creations by DSPO when a `DataSciencePipelinesApplication` (`DSPA`) is created. New test cases can be added by simply adding the deployment resources and their expected manifest pairs within the corresponding `case` folder. |
| 4 | + |
| 5 | +# Adding a new case example |
| 6 | + |
| 7 | +All declarative test cases can be found in `controllers/testdata/declarative`. |
| 8 | + |
| 9 | +Let's say we want a new test case `case_4` that tests that this `DSPA`... |
| 10 | + |
| 11 | +<details> |
| 12 | + |
| 13 | +<summary> dspa.yaml</summary> |
| 14 | + |
| 15 | +```yaml |
| 16 | +# dspa.yaml |
| 17 | +apiVersion: datasciencepipelinesapplications.opendatahub.io/v1alpha1 |
| 18 | +kind: DataSciencePipelinesApplication |
| 19 | +metadata: |
| 20 | + name: testdsp4 #ma |
| 21 | +spec: |
| 22 | + objectStorage: |
| 23 | + minio: |
| 24 | + image: minio:test4 |
| 25 | + mlpipelineUI: |
| 26 | + image: frontend:test4 |
| 27 | +``` |
| 28 | +</details> |
| 29 | +
|
| 30 | +...will deploy this configmap: |
| 31 | +
|
| 32 | +<details> |
| 33 | +
|
| 34 | +<summary> configmap.yaml</summary> |
| 35 | +
|
| 36 | +```yaml |
| 37 | +apiVersion: v1 |
| 38 | +data: |
| 39 | + artifact_script: |- |
| 40 | + #!/usr/bin/env sh |
| 41 | + push_artifact() { |
| 42 | + if [ -f "$2" ]; then |
| 43 | + tar -cvzf $1.tgz $2 |
| 44 | + aws s3 --endpoint ${ARTIFACT_ENDPOINT} cp $1.tgz s3://$ARTIFACT_BUCKET/artifacts/$PIPELINERUN/$PIPELINETASK/$1.tgz |
| 45 | + else |
| 46 | + echo "$2 file does not exist. Skip artifact tracking for $1" |
| 47 | + fi |
| 48 | + } |
| 49 | + push_log() { |
| 50 | + cat /var/log/containers/$PODNAME*$NAMESPACE*step-main*.log > step-main.log |
| 51 | + push_artifact main-log step-main.log |
| 52 | + } |
| 53 | + strip_eof() { |
| 54 | + if [ -f "$2" ]; then |
| 55 | + awk 'NF' $2 | head -c -1 > $1_temp_save && cp $1_temp_save $2 |
| 56 | + fi |
| 57 | + } |
| 58 | +kind: ConfigMap |
| 59 | +metadata: |
| 60 | + name: ds-pipeline-artifact-script-testdsp4 |
| 61 | + namespace: default |
| 62 | + labels: |
| 63 | + app: ds-pipeline-testdsp4 |
| 64 | + component: data-science-pipelines |
| 65 | + |
| 66 | +``` |
| 67 | + |
| 68 | +</details> |
| 69 | + |
| 70 | + |
| 71 | +We can do this by first creating a folder `controllers/testdata/declarative/case_4` |
| 72 | +Then adding the DSPA cr in: `controllers/testdata/declarative/case_4/deploy/dspa.yaml` (we want to the test case to `deploy` this DSPA) |
| 73 | +Then adding the configmap resource in: `controllers/testdata/declarative/case_4/expected/created/configmap.yaml` |
| 74 | +Each case requires a configmap, we can add one like this: |
| 75 | + |
| 76 | +```yaml |
| 77 | +Images: |
| 78 | + ApiServer: api-server:test4 |
| 79 | + Artifact: artifact-manager:test4 |
| 80 | + PersistentAgent: persistenceagent:test4 |
| 81 | + ScheduledWorkflow: scheduledworkflow:test4 |
| 82 | + ViewerCRD: viewercontroller:test4 |
| 83 | + Cache: ubi-minimal:test4 |
| 84 | + MoveResultsImage: busybox:test4 |
| 85 | + MlPipelineUI: frontend:test4 |
| 86 | + MariaDB: mariadb:test4 |
| 87 | + Minio: minio:test4 |
| 88 | +``` |
| 89 | +In `controllers/testdata/declarative/case_4/config.yaml` |
| 90 | + |
| 91 | +Then run the tests by running: |
| 92 | + |
| 93 | +`make test` |
| 94 | + |
| 95 | +You can add more expected resources by adding files in the `../expected/created` folder. To test resources that you do |
| 96 | +not expect to be created, add them in the `../expected/not_created` folders. Please see `/controllers/testutil/equalities.go` for |
| 97 | +all supported resources. |
| 98 | + |
| 99 | +For more complex tests, it is advised to create tests via logic. |
0 commit comments