Integration tests don't correctly handle status creation
Of the 3 ways I have tried to write the following test, none of them work. Here is a version of the test. Don't worry that it's not ergonomic and it doesn't make sense: that's the issue here. Focus on the value of `status.observedCRD.uid`.
```yaml
- name: Should not be able to set invalid observedCRD uid
initial: |
apiVersion: operator.openshift.io/v1alpha1
kind: CRDCompatibilityRequirement
metadata:
name: test-requirement
spec:
compatibilitySchema:
customResourceDefinition:
type: YAML
data: |
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: testrequirements.example.com
spec:
group: example.com
names:
kind: TestRequirement
plural: testrequirements
scope: Namespaced
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
requiredVersions:
defaultSet: StorageOnly
status:
observedCRD:
uid: "invalid-uid"
generation: 1
updated: |
apiVersion: operator.openshift.io/v1alpha1
kind: CRDCompatibilityRequirement
metadata:
name: test-requirement
spec:
compatibilitySchema:
customResourceDefinition:
type: YAML
data: |
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: testrequirements.example.com
spec:
group: example.com
names:
kind: TestRequirement
plural: testrequirements
scope: Namespaced
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
requiredVersions:
defaultSet: StorageOnly
status:
observedCRD:
uid: "invalid-uuid"
generation: 1
expectedError: "is invalid: [status.observedCRD.uid: Invalid value"
```
I initially wrote this as an `onCreate` test, but it passed because `onCreate` doesn't see to create `status`. That kinda makes sense, I guess, because `status` can only be updated.
So I wrote an `onUpdate` version where `initial` doesn't have a status and `updated` has invalid status. That passes. I don't understand why without looking deeper at the test framework. Feels like a bug.
So I wrote this version, where both `initial` and `updated` are identical, so `initial` is also invalid. This fails creating `initial` due to the validation I'm trying to test, namely that `uid` is not a valid `uuid`. This suggests my validation is working, but there's no option to assert failure for `initial` so the test fails.
I have to remove the test.
关闭于 2025-11-04 3 条评论