apiVersion: apiextensions.k8s.io/v1 # Hack because controller-gen complains if we don't have this
name: "[CustomNoUpgrade] ClusterVersion"
crd: 0000_00_cluster-version-operator_01_clusterversion-CustomNoUpgrade.crd.yaml
tests:
  onCreate:
  - name: Should be able to create a minimal ClusterVersion
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
  - name: Should allow image to be set
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          image: bar
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          image: bar
  - name: Should allow version to be set
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          version: 4.11.1
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          version: 4.11.1
  - name: Should allow architecture to be empty
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          architecture: ""
          version: 4.11.1
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          architecture: ""
          version: 4.11.1
  - name: Should allow architecture and version to be set
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          architecture: Multi
          version: 4.11.1
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          architecture: Multi
          version: 4.11.1
  - name: Version must be set if architecture is set
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          architecture: Multi
    expectedError: "Version must be set if Architecture is set"
  - name: Should not allow image and architecture to be set
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          architecture: Multi
          version: 4.11.1
          image: bar
    expectedError: "cannot set both Architecture and Image"
  - name: Should be able to create a ClusterVersion with base capability None, and additional capabilities baremetal and MachineAPI
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - baremetal
          - MachineAPI
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - baremetal
          - MachineAPI
  - name: Should not be able to create a ClusterVersion with base capability None, and additional capabilities baremetal without MachineAPI
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - baremetal
    expectedError: the `baremetal` capability requires the `MachineAPI` capability, which is neither explicitly or implicitly enabled in this cluster, please enable the `MachineAPI` capability
  - name: Should be able to create a ClusterVersion with base capability None, and additional capabilities marketplace and OperatorLifecycleManager
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - marketplace
          - OperatorLifecycleManager
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - marketplace
          - OperatorLifecycleManager
  - name: Should not be able to create a ClusterVersion with base capability None, and additional capabilities marketplace without OperatorLifecycleManager
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - marketplace
    expectedError: the `marketplace` capability requires the `OperatorLifecycleManager` capability, which is neither explicitly or implicitly enabled in this cluster, please enable the `OperatorLifecycleManager` capability
  - name: Should be able to set a custom signature store
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        signatureStores: 
          - url: "https://osus.ocp.com"
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        signatureStores: 
          - url: "https://osus.ocp.com"
  - name: Should be able to set multiple custom signature store
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        signatureStores: 
          - url: "https://osus1.ocp.com"
          - url: "https://osus2.ocp.com"
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        signatureStores: 
          - url: "https://osus1.ocp.com"
          - url: "https://osus2.ocp.com"
  - name: Invalid custom signature store should throw error
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        signatureStores: 
          - url: "osus1.ocp.com"
    expectedError: "url must be a valid absolute URL"
  - name: Should be able to unset the signature stores
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        signatureStores: []
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        signatureStores: []
  onUpdate:
  - name: Should not allow image to be set if architecture set
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          architecture: Multi
          version: 4.11.1
    updated: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          architecture: Multi
          version: 4.11.1
          image: bar
    expectedError: "cannot set both Architecture and Image"
  - name: Should not allow architecture to be set if image set
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          image: bar
    updated: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        desiredUpdate:
          architecture: Multi
          version: 4.11.1
          image: bar
    expectedError: "cannot set both Architecture and Image"
  - name: Should be able to add the baremetal capability with a ClusterVersion with base capability None, and implicitly enabled MachineAPI
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
      status:
        desired:
          version: foo
          image: foo
        observedGeneration: 1
        versionHash: foo
        availableUpdates:
        - version: foo
          image: foo
        capabilities:
          enabledCapabilities:
          - MachineAPI
    updated: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - baremetal
      status:
        desired:
          version: foo
          image: foo
        observedGeneration: 1
        versionHash: foo
        availableUpdates:
        - version: foo
          image: foo
        capabilities:
          enabledCapabilities:
          - MachineAPI
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - baremetal
      status:
        desired:
          version: foo
          image: foo
        observedGeneration: 1
        versionHash: foo
        availableUpdates:
        - version: foo
          image: foo
        capabilities:
          enabledCapabilities:
          - MachineAPI
  - name: Should be able to add the baremetal capability with a ClusterVersion with base capability None, with the Machine API capability
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
    updated: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - baremetal
          - MachineAPI
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - baremetal
          - MachineAPI
  - name: Should not be able to add the baremetal capability with a ClusterVersion with base capability None, and without MachineAPI
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
    updated: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - baremetal
    expectedError: the `baremetal` capability requires the `MachineAPI` capability, which is neither explicitly or implicitly enabled in this cluster, please enable the `MachineAPI` capability
  - name: Should be able to add the marketplace capability with a ClusterVersion with base capability None, and implicitly enabled OperatorLifecycleManager
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
      status:
        desired:
          version: foo
          image: foo
        observedGeneration: 1
        versionHash: foo
        availableUpdates:
        - version: foo
          image: foo
        capabilities:
          enabledCapabilities:
          - OperatorLifecycleManager
    updated: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - marketplace
      status:
        desired:
          version: foo
          image: foo
        observedGeneration: 1
        versionHash: foo
        availableUpdates:
        - version: foo
          image: foo
        capabilities:
          enabledCapabilities:
          - OperatorLifecycleManager
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - marketplace
      status:
        desired:
          version: foo
          image: foo
        observedGeneration: 1
        versionHash: foo
        availableUpdates:
        - version: foo
          image: foo
        capabilities:
          enabledCapabilities:
          - OperatorLifecycleManager
  - name: Should be able to add the marketplace capability with a ClusterVersion with base capability None, with the OperatorLifecycleManager capability
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
    updated: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - marketplace
          - OperatorLifecycleManager
    expected: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - marketplace
          - OperatorLifecycleManager
  - name: Should not be able to add the marketplace capability with a ClusterVersion with base capability None, and without OperatorLifecycleManager
    initial: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
    updated: |
      apiVersion: config.openshift.io/v1
      kind: ClusterVersion
      spec:
        clusterID: foo
        capabilities:
          baselineCapabilitySet: None
          additionalEnabledCapabilities:
          - marketplace
    expectedError: the `marketplace` capability requires the `OperatorLifecycleManager` capability, which is neither explicitly or implicitly enabled in this cluster, please enable the `OperatorLifecycleManager` capability
